IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40291


Ignore:
Timestamp:
Dec 13, 2017, 10:53:48 AM (8 years ago)
Author:
eugene
Message:

merge EAM development branch changes for DR2 into trunk (add PS1_V6 dvo format; change Mcal to McalPSF, McalAPER; change opihi int vectors to 64bit)

Location:
trunk/Ohana
Files:
173 edited
15 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/addstar/src/FilterStars.c

    r39473 r40291  
    7373    outcat->measure[N].airmass = airmass (image[0].secz, outcat->average[N].R, outcat->average[N].D, image[0].sidtime, image[0].latitude);
    7474    outcat->measure[N].az      = azimuth (15.0*image[0].sidtime - outcat->average[N].R, outcat->average[N].D, image[0].latitude);
    75     outcat->measure[N].Mcal    = image[0].Mcal;
     75    outcat->measure[N].McalPSF = image[0].McalPSF;
     76    outcat->measure[N].McalAPER= image[0].McalAPER;
    7677    outcat->measure[N].t       = image[0].tzero + 1e-4*outcat->measure[N].Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
    7778    outcat->measure[N].dt      = MTIME;
  • trunk/Ohana/src/addstar/src/LoadDataPMM.c

    r38553 r40291  
    234234    // altaz (&alt, &az, 15.0*image[0].sidtime - image[0].coords.crval1, image[0].coords.crval2, Latitude);
    235235
     236    // secz is in units of airmass
    236237    image[0].trate = 0.0;
    237238    image[0].secz = 1.0;
    238239    image[0].ccdnum = 0;
    239240
    240     // secz is in units milli-airmass
    241     image[0].Mcal = 0.0;
    242     image[0].Xm   = NAN_S_SHORT;
    243     image[0].flags = 0;
     241    image[0].McalPSF   = 0.0;
     242    image[0].McalAPER  = 0.0;
     243    image[0].McalChiSq = NAN;
     244    image[0].dMcal     = NAN;
     245    image[0].flags     = 0;
    244246
    245247    image[0].nstar = 0;
  • trunk/Ohana/src/addstar/src/ReadImageHeader.c

    r39457 r40291  
    265265  }
    266266
    267   /* secz is in units milli-airmass */
    268   image[0].Mcal = ZERO_POINT_OFFSET;
    269   image[0].dMcal = ZERO_POINT_ERROR;
    270   image[0].Xm   = NAN_S_SHORT;
    271   image[0].flags = 0;
     267  image[0].McalPSF   = ZERO_POINT_OFFSET;
     268  image[0].McalAPER = ZERO_POINT_OFFSET;
     269  image[0].dMcal     = ZERO_POINT_ERROR;
     270  image[0].McalChiSq = NAN;
     271  image[0].flags     = 0;
    272272
    273273  /* find expected number of stars */
  • trunk/Ohana/src/addstar/src/ReadSDSSHeader.c

    r16810 r40291  
    4747
    4848  // secz is in units milli-airmass
    49   image[0].Mcal = 0.0;
    50   image[0].Xm   = NAN_S_SHORT;
     49  image[0].McalPSF   = 0.0;
     50  image[0].McalAPER  = 0.0;
     51  image[0].McalChiSq = NAN;
     52  image[0].dMcal     = NAN;
    5153  image[0].code = 0;
    5254  memset (image[0].dummy, 0, sizeof(image[0].dummy));
  • trunk/Ohana/src/addstar/src/ReadStarsSDSS.c

    r39161 r40291  
    258258    altaz (&alt, &az, 15.0*images[N].sidtime - images[N].coords.crval1, images[N].coords.crval2, Latitude);
    259259
     260    // secz is in units of airmass
    260261    images[N].trate = clockRate * 1e-4;
    261262    images[N].secz = catalog->measure[0].airmass;
    262263    images[N].ccdnum = camcol;
    263264
    264     // secz is in units milli-airmass
    265     images[N].Mcal = 0.0;
    266     images[N].Xm   = NAN_S_SHORT;
    267     images[N].flags = 0;
     265    images[N].McalPSF   = 0.0;
     266    images[N].McalAPER  = 0.0;
     267    images[N].McalChiSq = NAN;
     268    images[N].dMcal     = NAN;
     269    images[N].flags     = 0;
    268270
    269271    images[N].nstar = Nstars;
  • trunk/Ohana/src/addstar/src/ReadStarsUKIRT.c

    r39161 r40291  
    196196    catalog->measure[i].FWy       = ToShortPixels(seeing);
    197197
    198     catalog->measure[i].Mcal      = Mcal;
     198    catalog->measure[i].McalPSF   = Mcal;
     199    catalog->measure[i].McalAPER  = Mcal;
    199200
    200201    catalog->measure[i].detID     = i;
     
    251252
    252253    // secz is in units milli-airmass
    253     images[N].Mcal = Mcal;
    254     images[N].Xm   = NAN_S_SHORT;
    255     images[N].flags = 0;
     254    images[N].McalPSF   = Mcal;
     255    images[N].McalAPER  = Mcal;
     256    images[N].McalChiSq = NAN;
     257    images[N].dMcal     = NAN;
     258    images[N].flags     = 0;
    256259
    257260    images[N].nstar = Nstars;
  • trunk/Ohana/src/addstar/src/SEDfit.c

    r38467 r40291  
    172172      outcat[0].measure[Nmeas].M         = table[0].row[minFit.row][0].mags[n] + minFit.Md;
    173173      outcat[0].measure[Nmeas].dM        = 0.0;
    174       outcat[0].measure[Nmeas].Mcal      = 0;
     174      outcat[0].measure[Nmeas].McalPSF   = 0;
     175      outcat[0].measure[Nmeas].McalAPER  = 0;
    175176      outcat[0].measure[Nmeas].t         = TIMEREF;
    176177      outcat[0].measure[Nmeas].averef    = Nave;
  • trunk/Ohana/src/addstar/src/calibrate.c

    r39457 r40291  
    7474  /* check if this reference code is an average magnitude */
    7575  if (Nsec != -1) {
    76     CalM0 = secfilt[Nsec].M;
    77     dCalM = secfilt[Nsec].dM;
     76    CalM0 = secfilt[Nsec].MpsfChp;
     77    dCalM = secfilt[Nsec].dMpsfChp;
    7878    found0 = TRUE;
    7979  }
     
    8282  Nsec  = GetPhotcodeNsec (CalC1);
    8383  if (Nsec != -1) {
    84     CalM1 = secfilt[Nsec].M;
     84    CalM1 = secfilt[Nsec].MpsfChp;
    8585    found1 = TRUE;
    8686  }
     
    8989  Nsec  = GetPhotcodeNsec (CalC2);
    9090  if (Nsec != -1) {
    91     CalM2 = secfilt[Nsec].M;
     91    CalM2 = secfilt[Nsec].MpsfChp;
    9292    found2 = TRUE;
    9393  }
     
    151151  if (MaxN == -1) {
    152152    fprintf (stderr, "no clean stars\n");
    153     image[0].Mcal = 10.000;
    154     image[0].dMcal = 10.000;
     153    image[0].McalPSF  = 10.000;
     154    image[0].McalAPER = 10.000;
     155    image[0].dMcal    = 10.000;
    155156    return;
    156157  }
     
    187188  if (Nkeep < 5) {
    188189    fprintf (stderr, "too few stars\n");
    189     image[0].Mcal = 10.000;
    190     image[0].dMcal = 10.000;
     190    image[0].McalPSF  = 10.000;
     191    image[0].McalAPER = 10.000;
     192    image[0].dMcal    = 10.000;
    191193    return;
    192194  }
     
    225227    fprintf (stdout, "ZERO_POINT_NSTARS    =    %4.0f\n", N);
    226228    // fprintf (stderr, "N: %.0f, mean: %f, wt mean: %f, stdev: %f, precision: %f\n", N, M1, Mw, M2, M2 / sqrt (N));
    227     image[0].Mcal = M1;
    228     image[0].dMcal = M2 / sqrt (N);
     229    image[0].McalPSF    = M1;
     230    image[0].McalAPER   = M1;
     231    image[0].dMcal      = M2 / sqrt (N);
    229232    image[0].nFitPhotom = N;
    230233  } else {
    231234    fprintf (stderr, "too few stars\n");
    232     image[0].Mcal = 10.000;
    233     image[0].dMcal = 10.000;
     235    image[0].McalPSF    = 10.000;
     236    image[0].McalAPER   = 10.000;
     237    image[0].dMcal      = 10.000;
    234238    image[0].nFitPhotom = 0;
    235239  }
  • trunk/Ohana/src/addstar/src/fakeimage.c

    r37807 r40291  
    110110    image[i+1].ccdnum = 0xff;
    111111
    112     image[i+1].Mcal  = 0.0;
    113     image[i+1].Xm    = NAN_S_SHORT;
     112    image[i+1].McalPSF   = 0.0;
     113    image[i+1].McalAPER  = 0.0;
     114    image[i+1].McalChiSq = NAN;
     115    image[i+1].dMcal     = NAN;
    114116    image[i+1].flags = 0;
    115117
     
    165167  image[0].secz = 1.0;
    166168  image[0].ccdnum = 0xff;
    167   image[0].Mcal = 0.0;
    168   image[0].Xm   = NAN_S_SHORT;
     169
     170  image[0].McalPSF   = 0.0;
     171  image[0].McalAPER  = 0.0;
     172  image[0].McalChiSq = NAN;
     173  image[0].dMcal     = NAN;
    169174  image[0].flags = 0;
     175
    170176  image[0].nstar = 0;
    171177
  • trunk/Ohana/src/addstar/src/find_matches.c

    r38986 r40291  
    212212        /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    213213        if (Nsec > -1) {
    214           if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].M)) {
    215             tgtcat[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     214          if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].MpsfChp)) {
     215            tgtcat[0].secfilt[n*Nsecfilt+Nsec].MpsfChp = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    216216          }
    217217        }
     
    305305      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    306306      if (Nsec > -1) {
    307         tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     307        tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].MpsfChp = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    308308      }
    309309
  • trunk/Ohana/src/addstar/src/find_matches_closest.c

    r38986 r40291  
    248248      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    249249      if (Nsec > -1) {
    250         if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].M)) {
    251           tgtcat[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     250        if (isnan(tgtcat[0].secfilt[n*Nsecfilt+Nsec].MpsfChp)) {
     251          tgtcat[0].secfilt[n*Nsecfilt+Nsec].MpsfChp = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    252252        }
    253253      }
     
    352352      /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    353353      if (Nsec > -1) {
    354         tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     354        tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].MpsfChp = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    355355      }
    356356
  • trunk/Ohana/src/addstar/src/find_matches_gaia.c

    r39926 r40291  
    267267    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
    268268    if (Nsec > -1) {
    269       tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].M = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
     269      tgtcat[0].secfilt[Nave*Nsecfilt+Nsec].MpsfChp = PhotCat (&tgtcat[0].measure[Nmeas], MAG_CLASS_PSF);
    270270    }
    271271
  • trunk/Ohana/src/addstar/src/find_proper.c

    r15036 r40291  
    104104       
    105105        /** add measurements for this star **/
    106         catalog[0].measure[Nmeas].dR  = 360000.0*(catalog[0].average[n].R - usno[N].R);
    107         catalog[0].measure[Nmeas].dD  = 360000.0*(catalog[0].average[n].D - usno[N].D);
    108         catalog[0].measure[Nmeas].M   = 1000.0*fabs(usno[N].r);
    109         catalog[0].measure[Nmeas].Mcal= 0;    /* above measurement is exact */
    110         catalog[0].measure[Nmeas].dM  = 100;  /* error in input files stored in thousandths of mag */
    111         catalog[0].measure[Nmeas].t   = 0;    /* a flag: if 0, image is not in database */
    112         catalog[0].measure[Nmeas].averef  = n;
    113         catalog[0].measure[Nmeas].photcode = USNO_RED;
    114         catalog[0].measure[Nmeas+1].dR  = catalog[0].measure[Nmeas].dR;
    115         catalog[0].measure[Nmeas+1].dD  = catalog[0].measure[Nmeas].dD;
    116         catalog[0].measure[Nmeas+1].M   = 1000.0*fabs(usno[N].b);
    117         catalog[0].measure[Nmeas+1].Mcal= 0;    /* above measurement is exact */
    118         catalog[0].measure[Nmeas+1].dM  = 100;  /* error in input files stored in thousandths of mag */
    119         catalog[0].measure[Nmeas+1].t   = 0;    /* a flag: if 0, image is not in database */
    120         catalog[0].measure[Nmeas+1].averef  = n;
     106        catalog[0].measure[Nmeas].dR         = 360000.0*(catalog[0].average[n].R - usno[N].R);
     107        catalog[0].measure[Nmeas].dD         = 360000.0*(catalog[0].average[n].D - usno[N].D);
     108        catalog[0].measure[Nmeas].M          = 1000.0*fabs(usno[N].r);
     109        catalog[0].measure[Nmeas].McalPSF    = 0;    /* above measurement is exact */
     110        catalog[0].measure[Nmeas].McalAPER   = 0;    /* above measurement is exact */
     111        catalog[0].measure[Nmeas].dM         = 100;  /* error in input files stored in thousandths of mag */
     112        catalog[0].measure[Nmeas].t          = 0;    /* a flag: if 0, image is not in database */
     113        catalog[0].measure[Nmeas].averef     = n;
     114        catalog[0].measure[Nmeas].photcode   = USNO_RED;
     115        catalog[0].measure[Nmeas+1].dR       = catalog[0].measure[Nmeas].dR;
     116        catalog[0].measure[Nmeas+1].dD       = catalog[0].measure[Nmeas].dD;
     117        catalog[0].measure[Nmeas+1].M        = 1000.0*fabs(usno[N].b);
     118        catalog[0].measure[Nmeas+1].McalPSF  = 0;    /* above measurement is exact */
     119        catalog[0].measure[Nmeas+1].McalAPER = 0;    /* above measurement is exact */
     120        catalog[0].measure[Nmeas+1].dM       = 100;  /* error in input files stored in thousandths of mag */
     121        catalog[0].measure[Nmeas+1].t        = 0;    /* a flag: if 0, image is not in database */
     122        catalog[0].measure[Nmeas+1].averef   = n;
    121123        catalog[0].measure[Nmeas+1].photcode = USNO_BLUE;
    122124        /* add flag in average to mark as matched with the USNO catalog */
  • trunk/Ohana/src/addstar/src/loadsupercos_plates.c

    r37807 r40291  
    7272    image[Nimage].apmifit = 0.0;
    7373    image[Nimage].dapmifit = 0.0;
    74     image[Nimage].Mcal = 0.0;
    75     image[Nimage].dMcal = 0.0;
    76     image[Nimage].Xm = 0.0;
     74    image[Nimage].McalPSF   = 0.0;
     75    image[Nimage].McalAPER  = 0.0;
     76    image[Nimage].McalChiSq = 0.0;
     77    image[Nimage].dMcal     = 0.0;
    7778
    7879    char photname[128];
  • trunk/Ohana/src/addstar/src/loadsupercos_rawdata.c

    r39457 r40291  
    8686
    8787        // XXX fix these
    88         newcat->measure[i].Mcal = 0.0;
     88        newcat->measure[i].McalPSF  = 0.0;
     89        newcat->measure[i].McalAPER = 0.0;
    8990        newcat->measure[i].dt = image[Ni].exptime;
    9091
  • trunk/Ohana/src/addstar/src/mkcmf.c

    r39457 r40291  
    3333float BAD_PSFQF_FRAC = 0.0;
    3434
     35static Coords coords;
    3536static float exptime = 1.0;
    36 static Coords coords;
     37static float aper_offset = 0.0;
     38static float aper_scale = 1.0; // this is set to 10^-0.4*aper_offset below is aper_offset is non-zero
     39static float kron_scale = 1.0; // extra offset between psf and kron mags
    3740
    3841static char reserved[] =  "Reserved space.  This line can be used to add a new FITS card.";
     
    178181  } 
    179182
     183  // aperture-like and psf-like mags may have different effective zero points. 
     184  // by setting this, we can check that we can apply different zero points
     185  if ((N = get_argument (argc, argv, "-aper-offset"))) {
     186    remove_argument (N, &argc, argv);
     187    aper_offset = atof (argv[N]);
     188    aper_scale = pow(10.0, -0.4*aper_offset);
     189    remove_argument (N, &argc, argv);
     190  } 
     191  if ((N = get_argument (argc, argv, "-kron-scale"))) {
     192    remove_argument (N, &argc, argv);
     193    kron_scale = atof (argv[N]);
     194    remove_argument (N, &argc, argv);
     195  } 
     196
    180197  // XXX note that the airmass and ra,dec,mjd can be inconsistent (for a given observatory location)
    181198  float airmass = 1.0;
     
    254271    struct timeval now;
    255272    gettimeofday (&now, NULL);
    256     long A = now.tv_sec + now.tv_usec * 1000000;
     273    int  B = getpid();
     274    long A = now.tv_sec - now.tv_usec * 1000000 + B*100000;
    257275    srand48(A);
    258276  }
     
    412430    gfits_modify (&header, "NINPUTS",         "%d", 1, 5);
    413431
     432    // if we have multiple stacks using the same input image IDs, we run into trouble
     433    int nFrame = 800 * drand48();
     434
    414435    int i;
    415436    for (i = 0; i < 5; i++) {
    416437      char field[64], expname[64];
    417438      sprintf (field, "INP_%04d", i);
    418       sprintf (expname, "o5745g01%02do.356%03d.wrp.1199763.skycell.1315.090.fits", i, i);
     439      sprintf (expname, "o5745g01%02do.%03d%03d.wrp.1199763.skycell.1315.090.fits", i, nFrame, i);
    419440      gfits_modify (&header, field, "%s", 1, expname);
    420441
     
    791812    stars[i].Y = Y[i];
    792813    stars[i].M = M[i];
    793     stars[i].Map = M[i] - 0.05;
     814    stars[i].Map = M[i] + aper_offset - 0.05;
    794815
    795816    // randomly give poor PSFQF values
     
    818839    stars[i].flags     = Flag[i];
    819840
    820     stars[i].kronFlux  = flux * 1.25;
    821     stars[i].kronFluxErr = fSN * flux * 1.25;
     841    stars[i].kronFlux  = flux * kron_scale * aper_scale;
     842    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
    822843  }
    823844
     
    852873    stars[i].Y = Y[i];
    853874    stars[i].M = M[i];
    854     stars[i].Map = M[i] - 0.05;
    855     stars[i].MapRaw = M[i] - 0.10;
     875    stars[i].Map = M[i] + aper_offset - 0.05;
     876    stars[i].MapRaw = M[i] + aper_offset - 0.10;
    856877
    857878    stars[i].Flux = flux;
     
    888909    stars[i].flags     = Flag[i];
    889910
    890     stars[i].kronFlux  = flux * 1.25;
    891     stars[i].kronFluxErr = fSN * flux * 1.25;
     911    stars[i].kronFlux  = flux * kron_scale * aper_scale;
     912    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
    892913  }
    893914
     
    933954    stars[i].dFlux = flux * fSN;
    934955
    935     stars[i].Map = M[i] - 0.05;
    936     stars[i].MapRaw = M[i] - 0.10;
     956    stars[i].Map = M[i] + aper_offset - 0.05;
     957    stars[i].MapRaw = M[i] + aper_offset - 0.10;
    937958
    938959    stars[i].apRadius = 8.0;
     
    9831004    stars[i].Mrh       = FX;
    9841005
    985     stars[i].kronFlux  = flux * 1.25;
    986     stars[i].kronFluxErr = fSN * flux * 1.25;
    987 
    988     stars[i].kronInner = fSN * flux * 0.9;
    989     stars[i].kronOuter = fSN * flux * 1.5;
     1006    stars[i].kronFlux  = flux * kron_scale * aper_scale;
     1007    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
     1008
     1009    stars[i].kronInner = fSN * flux * 0.9 * aper_scale;
     1010    stars[i].kronOuter = fSN * flux * 1.5 * aper_scale;
    9901011
    9911012    stars[i].skyLimitRad = 1;
     
    10401061    stars[i].dFlux = flux * fSN;
    10411062
    1042     stars[i].Map = M[i] - 0.05;
    1043     stars[i].MapRaw = M[i] - 0.10;
     1063    stars[i].Map = M[i] + aper_offset - 0.05;
     1064    stars[i].MapRaw = M[i] + aper_offset - 0.10;
    10441065
    10451066    stars[i].apRadius = 8.0;
     
    10901111    stars[i].Mrh       = FX;
    10911112
    1092     stars[i].kronFlux  = flux * 1.25;
    1093     stars[i].kronFluxErr = fSN * flux * 1.25;
    1094 
    1095     stars[i].kronInner = fSN * flux * 0.9;
    1096     stars[i].kronOuter = fSN * flux * 1.5;
     1113    stars[i].kronFlux  = flux * kron_scale * aper_scale;
     1114    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
     1115
     1116    stars[i].kronInner = fSN * flux * 0.9 * aper_scale;
     1117    stars[i].kronOuter = fSN * flux * 1.5 * aper_scale;
    10971118
    10981119    // stars[i].skyLimitRad = 1;
     
    11441165    stars[i].dFlux = flux * fSN;
    11451166
    1146     stars[i].Map = M[i] - 0.05;
    1147     stars[i].MapRaw = M[i] - 0.10;
     1167    stars[i].Map = M[i] + aper_offset - 0.05;
     1168    stars[i].MapRaw = M[i] + aper_offset - 0.10;
    11481169
    11491170    stars[i].apRadius = 8.0;
     
    11851206    stars[i].Mrh = FX;
    11861207
    1187     stars[i].kronFlux = flux * 1.25;
    1188     stars[i].kronFluxErr = fSN * flux * 1.25;
    1189 
    1190     stars[i].kronInner = fSN * flux * 0.9;
    1191     stars[i].kronOuter = fSN * flux * 1.5;
     1208    stars[i].kronFlux = flux * kron_scale * aper_scale;
     1209    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
     1210
     1211    stars[i].kronInner = fSN * flux * 0.9 * aper_scale;
     1212    stars[i].kronOuter = fSN * flux * 1.5 * aper_scale;
    11921213
    11931214    stars[i].chipNum = 1;
     
    12701291    stars[i].dFlux = flux * fSN;
    12711292
    1272     stars[i].Map = M[i] - 0.05;
    1273     stars[i].MapRaw = M[i] - 0.10;
     1293    stars[i].Map = M[i] + aper_offset - 0.05;
     1294    stars[i].MapRaw = M[i] + aper_offset - 0.10;
    12741295
    12751296    stars[i].apRadius = 8.0;
     
    13471368    stars[i].srcChipY   = Y[i] + 10.0;
    13481369
    1349     stars[i].kronFlux  = flux * 1.25;
    1350     stars[i].kronFluxErr = fSN * flux * 1.25;
    1351 
    1352     stars[i].kronInner = fSN * flux * 0.9;
    1353     stars[i].kronOuter = fSN * flux * 1.5;
     1370    stars[i].kronFlux  = flux * kron_scale * aper_scale;
     1371    stars[i].kronFluxErr = fSN * flux * kron_scale * aper_scale;
     1372
     1373    stars[i].kronInner = fSN * flux * 0.9 * aper_scale;
     1374    stars[i].kronOuter = fSN * flux * 1.5 * aper_scale;
    13541375
    13551376    stars[i].skyLimitRad = 1;
  • trunk/Ohana/src/checkastro/src/BrightCatalog.c

    r37043 r40291  
    7171    GET_COLUMN(dD,        "DEC_OFF",    float);
    7272    GET_COLUMN(M,         "MAG_SYS",    float);
    73     GET_COLUMN(Mcal,      "MAG_CAL",    float);
     73    GET_COLUMN(McalPSF,   "MCAL_PSF",   float);
     74    GET_COLUMN(McalAPER,  "MCAL_APER",  float);
    7475    GET_COLUMN(dM,        "MAG_ERR",    float);
    7576    GET_COLUMN(airmass,   "AIRMASS",    float);
     
    9596      measure[i].dD        = dD[i];
    9697      measure[i].M         = M[i];
    97       measure[i].Mcal      = Mcal[i];
     98      measure[i].McalPSF   = McalPSF[i];
     99      measure[i].McalAPER  = McalAPER[i];
    98100      measure[i].dM        = dM[i];
    99101      measure[i].airmass   = airmass[i];
     
    116118    free (dD      );
    117119    free (M       );
    118     free (Mcal    );
     120    free (McalPSF );
     121    free (McalAPER);
    119122    free (dM      );
    120123    free (airmass );
     
    270273    ALLOCATE (secfilt, SecFilt, Nrow);
    271274    for (i = 0; i < Nrow; i++) {
    272       secfilt[i].M     = M[i];         
    273       secfilt[i].dM    = dM[i];
    274       secfilt[i].Mchisq= Mchisq[i];
    275       secfilt[i].flags = flags[i];
    276       secfilt[i].Ncode = Ncode[i];
    277       secfilt[i].Nused = Nused[i];
    278       secfilt[i].M_20  = M_20[i];
    279       secfilt[i].M_80  = M_80[i];
     275      secfilt[i].MpsfChp  = M[i];         
     276      secfilt[i].dMpsfChp = dM[i];
     277      secfilt[i].Mchisq   = Mchisq[i];
     278      secfilt[i].flags    = flags[i];
     279      secfilt[i].Ncode    = Ncode[i];
     280      secfilt[i].Nused    = Nused[i];
     281      secfilt[i].M_20     = M_20[i];
     282      secfilt[i].M_80     = M_80[i];
    280283    }
    281284    fprintf (stderr, "loaded data for %lld averages\n", (long long) Nrow);
     
    366369    float *dD        ; ALLOCATE (dD       ,  float, catalog->Nmeasure);
    367370    float *M         ; ALLOCATE (M        ,  float, catalog->Nmeasure);
    368     float *Mcal      ; ALLOCATE (Mcal     ,  float, catalog->Nmeasure);
     371    float *McalPSF   ; ALLOCATE (McalPSF  ,  float, catalog->Nmeasure);
     372    float *McalAPER  ; ALLOCATE (McalAPER ,  float, catalog->Nmeasure);
    369373    float *dM        ; ALLOCATE (dM       ,  float, catalog->Nmeasure);
    370374    float *airmass   ; ALLOCATE (airmass  ,  float, catalog->Nmeasure);
     
    388392      dD[i]       = measure[i].dD       ;
    389393      M[i]        = measure[i].M        ;
    390       Mcal[i]     = measure[i].Mcal     ;
     394      McalPSF[i]  = measure[i].McalPSF  ;
     395      McalAPER[i] = measure[i].McalAPER ;
    391396      dM[i]       = measure[i].dM       ;
    392397      airmass[i]  = measure[i].airmass  ;
     
    409414    gfits_set_bintable_column (&theader, &ftable, "DEC_OFF",    dD,        catalog->Nmeasure);
    410415    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    411     gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     416    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",   McalPSF,   catalog->Nmeasure);
     417    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER,  catalog->Nmeasure);
    412418    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",    dM,        catalog->Nmeasure);
    413419    gfits_set_bintable_column (&theader, &ftable, "AIRMASS",    airmass,   catalog->Nmeasure);
     
    428434    free (dD      );
    429435    free (M       );
    430     free (Mcal    );
     436    free (McalPSF );
     437    free (McalAPER);
    431438    free (dM      );
    432439    free (airmass );
     
    652659    SecFilt *secfilt = catalog->secfilt;
    653660    for (i = 0; i < Nsec; i++) {
    654       M     [i]       = secfilt[i].M      ;
    655       dM    [i]       = secfilt[i].dM     ;
    656       Mchisq[i]       = secfilt[i].Mchisq ;
    657       flags [i]       = secfilt[i].flags  ;
    658       Ncode [i]       = secfilt[i].Ncode  ;
    659       Nused [i]       = secfilt[i].Nused  ;
    660       M_20  [i]       = secfilt[i].M_20   ;
    661       M_80  [i]       = secfilt[i].M_80   ;
     661      M     [i]       = secfilt[i].MpsfChp ;
     662      dM    [i]       = secfilt[i].dMpsfChp;
     663      Mchisq[i]       = secfilt[i].Mchisq  ;
     664      flags [i]       = secfilt[i].flags   ;
     665      Ncode [i]       = secfilt[i].Ncode   ;
     666      Nused [i]       = secfilt[i].Nused   ;
     667      M_20  [i]       = secfilt[i].M_20    ;
     668      M_80  [i]       = secfilt[i].M_80    ;
    662669    }
    663670
  • trunk/Ohana/src/delstar/Makefile

    r39692 r40291  
    3232$(SRC)/delete_duplicate_measures.$(ARCH).o \
    3333$(SRC)/delete_measures_by_match.$(ARCH).o \
     34$(SRC)/delete_measures_by_detID.$(ARCH).o \
    3435$(SRC)/delete_fix_LAP.$(ARCH).o \
    3536$(SRC)/delete_fix_LAP_edges.$(ARCH).o \
     
    5859$(SRC)/delete_duplicate_measures.$(ARCH).o \
    5960$(SRC)/delete_measures_by_match.$(ARCH).o \
     61$(SRC)/delete_measures_by_detID.$(ARCH).o \
    6062$(SRC)/delete_fix_LAP.$(ARCH).o \
    6163$(SRC)/delete_fix_LAP_edges.$(ARCH).o \
  • trunk/Ohana/src/delstar/include/delstar.h

    r39926 r40291  
    9696int   SKIP_IMAGES;
    9797char *BACKUP_EXTNAME;
     98char *DELLIST_FILENAME;
    9899
    99100time_t    START;
     
    105106
    106107int    MODE;
    107 enum {MODE_NONE, MODE_IMAGENAME, MODE_IMAGEFILE, MODE_TIME, MODE_ORPHAN, MODE_MISSED, MODE_PHOTCODES, MODE_DUP_IMAGES, MODE_DUP_MEASURES, MODE_DELETE_MEASURES_BY_MATCH, MODE_FIX_LAP, MODE_FIX_LAP_STATS, MODE_FIX_LAP_EDGES, MODE_FIX_LAP_EDGES_DELETE};
     108enum {MODE_NONE, MODE_IMAGENAME, MODE_IMAGEFILE, MODE_TIME, MODE_ORPHAN, MODE_MISSED, MODE_PHOTCODES, MODE_DUP_IMAGES, MODE_DUP_MEASURES, MODE_DELETE_MEASURES_BY_MATCH, MODE_DELETE_MEASURES_BY_DETID, MODE_FIX_LAP, MODE_FIX_LAP_STATS, MODE_FIX_LAP_EDGES, MODE_FIX_LAP_EDGES_DELETE};
    108109
    109110char DateKeyword[64], DateMode[64], UTKeyword[64], MJDKeyword[64], JDKeyword[64];
     
    230231int delete_fix_LAP_edges_drop_measures (Catalog *catalog, MeasureEdge *measure_edge, off_t Nmeasure_edge, int catIDcount);
    231232int delete_fix_LAP_edges_delete_parallel (SkyList *sky);
     233
     234typedef struct {
     235  int  catID;
     236  int *objID;
     237  int *detID;
     238  int *imageID;
     239  int NdetID;
     240} CatIDGroup;
     241
     242int dvo_catalog_subset_backup (Catalog *catalog, char *suffix);
     243void isortthree (int *X, int *Y, int *Z, int N);
     244int thisCatID (int *catID, int NcatID, int index);
     245int needCatID (int *catID, int NcatID, int index);
     246int delete_measures_by_detID_catalog (Catalog *catalog, CatIDGroup *catIDgroup);
     247int delete_measures_by_detID_parallel (SkyList *sky);
     248int delete_measures_by_detID ();
     249
  • trunk/Ohana/src/delstar/src/args.c

    r39926 r40291  
    202202  }
    203203
     204  DELLIST_FILENAME = NULL;
     205  if ((N = get_argument (argc, argv, "-delete-measures-by-detID"))) {
     206    if (MODE != MODE_NONE) usage();
     207    MODE = MODE_DELETE_MEASURES_BY_DETID;
     208    remove_argument (N, &argc, argv);
     209    SKIP_IMAGES = TRUE; // we do not need to load the images for -dup-measures
     210    DELLIST_FILENAME = strcreate (argv[N]);
     211    remove_argument (N, &argc, argv);
     212  }
     213
    204214  DELETE_MIN_DET_ID = 0;
    205215  DELETE_MAX_DET_ID = 0;
     
    374384  FREE (PHOTCODE_LIST);
    375385  FREE (IMSTATS_FILE);
     386  FREE (DELLIST_FILENAME);
    376387}
    377388
     
    494505    remove_argument (N, &argc, argv);
    495506    SKIP_IMAGES = TRUE; // we do not need to load the images for -dup-measures
     507  }
     508
     509  DELLIST_FILENAME = NULL;
     510  if ((N = get_argument (argc, argv, "-delete-measures-by-detID"))) {
     511    if (MODE != MODE_NONE) usage();
     512    MODE = MODE_DELETE_MEASURES_BY_DETID;
     513    remove_argument (N, &argc, argv);
     514    SKIP_IMAGES = TRUE; // we do not need to load the images for -dup-measures
     515    DELLIST_FILENAME = strcreate (argv[N]);
     516    remove_argument (N, &argc, argv);
    496517  }
    497518
     
    603624  FREE (MEASURE_EDGE_FILE);
    604625  FREE (IMSTATS_FILE);
     626  FREE (DELLIST_FILENAME);
    605627}
    606628
  • trunk/Ohana/src/delstar/src/delstar.c

    r39692 r40291  
    3434    case MODE_DELETE_MEASURES_BY_MATCH:
    3535      if (!delete_measures_by_match ()) exit (1);
     36      delstar_args_free ();
     37      ohana_memcheck (TRUE);
     38      ohana_memdump (TRUE);
     39      exit (0);
     40      break;
     41    case MODE_DELETE_MEASURES_BY_DETID:
     42      if (!delete_measures_by_detID ()) exit (1);
    3643      delstar_args_free ();
    3744      ohana_memcheck (TRUE);
  • trunk/Ohana/src/delstar/src/delstar_client.c

    r39692 r40291  
    3737    case MODE_DELETE_MEASURES_BY_MATCH:
    3838      if (!delete_measures_by_match ()) exit (1);
     39      delstar_args_free ();
     40      ohana_memcheck (TRUE);
     41      ohana_memdump (TRUE);
     42      exit (0);
     43      break;
     44    case MODE_DELETE_MEASURES_BY_DETID:
     45      if (!delete_measures_by_detID ()) exit (1);
    3946      delstar_args_free ();
    4047      ohana_memcheck (TRUE);
  • trunk/Ohana/src/delstar/src/gimages.c

    r39457 r40291  
    8888
    8989  /* secz is in units milli-airmass */
    90   image[0].Mcal = ALPHA*(image[0].secz - 1.000);
    91   image[0].Xm   = NAN_S_SHORT;
     90  image[0].McalPSF   = ALPHA*(image[0].secz - 1.000);
     91  image[0].McalAPER  = ALPHA*(image[0].secz - 1.000);
     92  image[0].McalChiSq = NAN_S_SHORT;
    9293
    9394  free (header.buffer);
  • trunk/Ohana/src/dvolens/src/update_objects_catalog.c

    r39611 r40291  
    219219
    220220      // relphot sets measure->Mcal (setMcalOutput.c, called by setMrelFinal.c)
    221       float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure->Mcal;
     221      // XXX : I'm using McalAPER since these lens measurements are aperture-like, right?
     222      float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure->McalAPER;
    222223      float Fcal = 3630.8 * MagToFlux(Mcal);
    223224
  • trunk/Ohana/src/dvomerge/src/build_links.c

    r40127 r40291  
    701701  off_t *next_galphot;
    702702
    703   if (galphot) return NULL;
     703  if (!galphot) return NULL;
    704704  if (SKIP_GALPHOT) return NULL;
    705705
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r39926 r40291  
    367367      // secfilt tables of input and output are the same
    368368      for (k = 0; k < NsecfiltIn; k++) {
    369         if ( isfinite(output[0].secfilt[n*NsecfiltIn+k].M)) continue;
    370         if (!isfinite( input[0].secfilt[N*NsecfiltIn+k].M)) continue;
     369        if ( isfinite(output[0].secfilt[n*NsecfiltIn+k].MpsfChp)) continue;
     370        if (!isfinite( input[0].secfilt[N*NsecfiltIn+k].MpsfChp)) continue;
    371371        output[0].secfilt[n*NsecfiltIn+k] = input[0].secfilt[N*NsecfiltIn+k];
    372372      }
     
    378378        int outputIndex = n * NsecfiltOut + secfiltMap[k];
    379379       
    380         if ( isfinite(output[0].secfilt[outputIndex].M)) continue;
    381         if (!isfinite( input[0].secfilt[N*NsecfiltIn+k].M)) continue;
     380        if ( isfinite(output[0].secfilt[outputIndex].MpsfChp)) continue;
     381        if (!isfinite( input[0].secfilt[N*NsecfiltIn+k].MpsfChp)) continue;
    382382        output[0].secfilt[outputIndex] = input[0].secfilt[N*NsecfiltIn+k];
    383383      }
     
    489489      }
    490490   
    491       if (isfinite(input[0].secfilt[N*NsecfiltIn+j].M)) {
     491      if (isfinite(input[0].secfilt[N*NsecfiltIn+j].MpsfChp)) {
    492492        output[0].secfilt[outputIndex] = input[0].secfilt[N*NsecfiltIn+j];
    493493      }
  • trunk/Ohana/src/dvopsps/include/dvopsps.h

    r39112 r40291  
    1919  float raErr;
    2020  float decErr;
    21   float zp;
    22   float zpFactor;
     21  float zpPSF;
     22  float zpFactorPSF;
     23  float zpAPER;
     24  float zpFactorAPER;
    2325  float telluricExt;
    2426  float airmass;
     
    4547
    4648int          SAVE_REMOTE;
     49int          TEST_MODE;
    4750
    4851int          PARALLEL;
  • trunk/Ohana/src/dvopsps/src/DetectionOps.c

    r39547 r40291  
    5656  GET_COLUMN(raErr       , "raErr",       float);
    5757  GET_COLUMN(decErr      , "decErr",      float);
    58   GET_COLUMN(zp          , "zp",          float);
    59   GET_COLUMN(zpFactor    , "zpFactor",    float);
     58  GET_COLUMN(zpPSF       , "zpPSF",       float);
     59  GET_COLUMN(zpFactorPSF , "zpFactorPSF", float);
     60  GET_COLUMN(zpAPER      , "zpAPER",      float);
     61  GET_COLUMN(zpFactorAPER, "zpFactorAPER",float);
    6062  GET_COLUMN(telluricExt , "telluricExt", float);
    6163  GET_COLUMN(airmass     , "airmass",     float);
     
    8486    detections[i].raErr        = raErr[i];     
    8587    detections[i].decErr       = decErr[i];     
    86     detections[i].zp           = zp[i];         
    87     detections[i].zpFactor     = zpFactor[i];         
     88    detections[i].zpPSF        = zpPSF[i];         
     89    detections[i].zpFactorPSF  = zpFactorPSF[i];         
     90    detections[i].zpAPER       = zpAPER[i];         
     91    detections[i].zpFactorAPER = zpFactorAPER[i];         
    8892    detections[i].telluricExt  = telluricExt[i];     
    8993    detections[i].airmass      = airmass[i];   
     
    110114  free (raErr      );
    111115  free (decErr     );
    112   free (zp         );
    113   free (zpFactor   );
     116  free (zpPSF      );
     117  free (zpFactorPSF);
     118  free (zpAPER      );
     119  free (zpFactorAPER);
    114120  free (telluricExt);
    115121  free (airmass    );
     
    180186  gfits_define_bintable_column (&theader, "E", "raErr",       NULL, NULL, 1.0, 0.0);
    181187  gfits_define_bintable_column (&theader, "E", "decErr",      NULL, NULL, 1.0, 0.0);
    182   gfits_define_bintable_column (&theader, "E", "zp",          NULL, NULL, 1.0, 0.0);
    183   gfits_define_bintable_column (&theader, "E", "zpFactor",    NULL, NULL, 1.0, 0.0);
     188  gfits_define_bintable_column (&theader, "E", "zpPSF",          NULL, NULL, 1.0, 0.0);
     189  gfits_define_bintable_column (&theader, "E", "zpFactorPSF",    NULL, NULL, 1.0, 0.0);
     190  gfits_define_bintable_column (&theader, "E", "zpAPER",         NULL, NULL, 1.0, 0.0);
     191  gfits_define_bintable_column (&theader, "E", "zpFactorAPER",   NULL, NULL, 1.0, 0.0);
    184192  gfits_define_bintable_column (&theader, "E", "telluricExt", NULL, NULL, 1.0, 0.0);
    185193  gfits_define_bintable_column (&theader, "E", "airmass",     NULL, NULL, 1.0, 0.0);
     
    208216  float      *raErr       ; ALLOCATE (raErr       ,  float,    Ndetections);
    209217  float      *decErr      ; ALLOCATE (decErr      ,  float,    Ndetections);
    210   float      *zp          ; ALLOCATE (zp          ,  float,    Ndetections);
    211   float      *zpFactor    ; ALLOCATE (zpFactor    ,  float,    Ndetections);
     218  float      *zpPSF       ; ALLOCATE (zpPSF       ,  float,    Ndetections);
     219  float      *zpFactorPSF ; ALLOCATE (zpFactorPSF ,  float,    Ndetections);
     220  float      *zpAPER      ; ALLOCATE (zpAPER      ,  float,    Ndetections);
     221  float      *zpFactorAPER; ALLOCATE (zpFactorAPER,  float,    Ndetections);
    212222  float      *telluricExt ; ALLOCATE (telluricExt ,  float,    Ndetections);
    213223  float      *airmass     ; ALLOCATE (airmass     ,  float,    Ndetections);
     
    234244    raErr[i]       = detections[i].raErr       ;
    235245    decErr[i]      = detections[i].decErr      ;
    236     zp[i]          = detections[i].zp          ;
    237     zpFactor[i]    = detections[i].zpFactor    ;
     246    zpPSF[i]       = detections[i].zpPSF       ;
     247    zpFactorPSF[i] = detections[i].zpFactorPSF ;
     248    zpAPER[i]      = detections[i].zpAPER      ;
     249    zpFactorAPER[i]= detections[i].zpFactorAPER;
    238250    telluricExt[i] = detections[i].telluricExt ;
    239251    airmass[i]     = detections[i].airmass     ;
     
    260272  gfits_set_bintable_column (&theader, &ftable, "raErr",       raErr       , Ndetections);
    261273  gfits_set_bintable_column (&theader, &ftable, "decErr",      decErr      , Ndetections);
    262   gfits_set_bintable_column (&theader, &ftable, "zp",          zp          , Ndetections);
    263   gfits_set_bintable_column (&theader, &ftable, "zpFactor",    zpFactor    , Ndetections);
     274  gfits_set_bintable_column (&theader, &ftable, "zpPSF",       zpPSF       , Ndetections);
     275  gfits_set_bintable_column (&theader, &ftable, "zpFactorPSF", zpFactorPSF , Ndetections);
     276  gfits_set_bintable_column (&theader, &ftable, "zpAPER",      zpAPER      , Ndetections);
     277  gfits_set_bintable_column (&theader, &ftable, "zpFactorAPER",zpFactorAPER, Ndetections);
    264278  gfits_set_bintable_column (&theader, &ftable, "telluricExt", telluricExt , Ndetections);
    265279  gfits_set_bintable_column (&theader, &ftable, "airmass",     airmass     , Ndetections);
     
    284298  free (raErr       );
    285299  free (decErr      );
    286   free (zp          );
    287   free (zpFactor    );
     300  free (zpPSF       );
     301  free (zpFactorPSF );
     302  free (zpAPER      );
     303  free (zpFactorAPER);
    288304  free (telluricExt );
    289305  free (airmass     );
  • trunk/Ohana/src/dvopsps/src/initialize_dvopsps.c

    r38674 r40291  
    123123  if ((N = get_argument (argc, argv, "-insert-remote"))) {
    124124    SAVE_REMOTE = FALSE;
     125    remove_argument (N, &argc, argv);
     126  }
     127
     128  TEST_MODE = FALSE;
     129  if ((N = get_argument (argc, argv, "-test-mode"))) {
     130    TEST_MODE = TRUE;
    125131    remove_argument (N, &argc, argv);
    126132  }
     
    361367  }
    362368
     369  TEST_MODE = FALSE;
     370  if ((N = get_argument (argc, argv, "-test-mode"))) {
     371    TEST_MODE = TRUE;
     372    remove_argument (N, &argc, argv);
     373  }
     374
    363375  HOST_ID = 0;
    364376  if ((N = get_argument (argc, argv, "-hostID"))) {
  • trunk/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps.c

    r38471 r40291  
    136136    snprintf (tmpline, 1024, "%s -dbname %s", command, DATABASE_NAME); strcpy (command, tmpline);
    137137
    138     if (VERBOSE)    { snprintf (tmpline, 1024, "%s -v",      command);             strcpy (command, tmpline); }
    139     if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s", command, SINGLE_CPT); strcpy (command, tmpline); }
     138    if (VERBOSE)    { snprintf (tmpline, 1024, "%s -v",         command);             strcpy (command, tmpline); }
     139    if (TEST_MODE)  { snprintf (tmpline, 1024, "%s -test-mode", command);             strcpy (command, tmpline); }
     140    if (SINGLE_CPT) { snprintf (tmpline, 1024, "%s -cpt %s",    command, SINGLE_CPT); strcpy (command, tmpline); }
    140141
    141142    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps_catalog.c

    r39593 r40291  
    4343    }
    4444
    45     int hasPS1 = FALSE;
    46     for (int j = 0; !hasPS1 && (j < Nsecfilt); j++) {
    47       if (secfilt[i*Nsecfilt + j].flags & hasPS1_flag) hasPS1 = TRUE;
    48     }
    49     if (!hasPS1) continue; // skip non-PS1 data
     45    if (!TEST_MODE) {
     46      int hasPS1 = FALSE;
     47      for (int j = 0; !hasPS1 && (j < Nsecfilt); j++) {
     48        if (secfilt[i*Nsecfilt + j].flags & hasPS1_flag) hasPS1 = TRUE;
     49      }
     50      if (!hasPS1) continue; // skip non-PS1 data
     51    }
    5052
    5153    off_t m = average[i].lensobjOffset;
  • trunk/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r39645 r40291  
    183183
    184184  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, catID, ");
    185   PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, zpFactor, telluricExt, airmass, expTime, ");
     185  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zpPSF, zpFactorPSF, zpAPER, zpFactorAPER, telluricExt, airmass, expTime, ");
    186186  PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags, objflags) VALUES \n");
    187187
     
    254254  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
    255255  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
    256   PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
    257   PRINT_FLOAT(buffer, detection->zpFactor,    "%.6e, ");
     256  PRINT_FLOAT(buffer, detection->zpPSF,       "%.6f, ");
     257  PRINT_FLOAT(buffer, detection->zpFactorPSF, "%.6e, ");
     258  PRINT_FLOAT(buffer, detection->zpAPER,      "%.6f, ");
     259  PRINT_FLOAT(buffer, detection->zpFactorAPER,"%.6e, ");
    258260  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
    259261  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
     
    305307int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
    306308
     309  // myAbort ("check on measure->McalPSF vs McalAPER");
     310
    307311  PhotCode *code = GetPhotcodebyCode(measure->photcode);
    308312
     
    311315  float Mflat       = isfinite(measure->Mflat) ? measure->Mflat : 0.0;
    312316  float nominalZP   = code->C * 0.001 + code->K * (measure->airmass - 1);
    313   float zp          = nominalZP - measure->Mcal - Mflat;
    314   float zpFactor    = pow(10.0, -0.4*zp + 3.56);
    315   float telluricExt = - measure->Mcal;
     317  float zpPSF       = nominalZP - measure->McalPSF - Mflat;
     318  float zpFactorPSF = pow(10.0, -0.4*zpPSF + 3.56);
     319  float zpAPER      = nominalZP - measure->McalAPER - Mflat;
     320  float zpFactorAPER= pow(10.0, -0.4*zpAPER + 3.56);
     321  float telluricExt = - measure->McalPSF;
    316322  float expTime     = pow(10.0, 0.4 * measure->dt);
    317323  float airmass     = measure->airmass;
     
    329335  detection->decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
    330336
    331   detection->zp           = zp;
    332   detection->zpFactor     = zpFactor;
     337  detection->zpPSF        = zpPSF;
     338  detection->zpFactorPSF  = zpFactorPSF;
     339  detection->zpAPER       = zpAPER;
     340  detection->zpFactorAPER = zpFactorAPER;
    333341  detection->telluricExt  = telluricExt;
    334342  detection->airmass      = airmass;
     
    337345  // XXX clean this up with dvo_photcode_ops calls:
    338346  // if (isfinite(measure->FluxPSF) && (measure->FluxPSF < 0.0))
    339   detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zp);
    340   detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zp);
    341   detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zp);
     347  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zpPSF);
     348  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zpAPER);
     349  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zpAPER);
    342350
    343351  detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
  • trunk/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r39650 r40291  
    11# include "dvopsps.h"
    22# define DEBUG 0
     3
     4int Format_PSX_Name (char *buffer, int Nbuffer, double tmp_ra, double tmp_dec);
    35
    46int insert_objects_dvopsps_catalog (Catalog *catalog, char *basename, MYSQL *mysql) {
     
    110112                 "RA_ERR        FLOAT,    "     
    111113                 "DEC_ERR       FLOAT,    "
    112                  "IAU_NAME      VARCHAR(32), "
    113114                 "PSO_NAME      VARCHAR(32), "
     115                 "PSX_NAME      VARCHAR(32), "
    114116                 "CHISQ_POS     FLOAT,    "   
    115117                 "CHISQ_PM      FLOAT,    "   
     
    219221                 "RA_ERR,        "     
    220222                 "DEC_ERR,       "
    221                  "IAU_NAME,      "
    222223                 "PSO_NAME,      "
     224                 "PSX_NAME,      "
    223225                 "CHISQ_POS,     "   
    224226                 "CHISQ_PM,      "   
     
    267269  double Tmean = average->Tmean == 0 ? NAN : ohana_sec_to_mjd (average->Tmean);
    268270
    269 // XXX this bit could/should be autocoded...
     271  char coord_buffer[128];
     272
     273  // XXX this bit could/should be autocoded...
    270274  PrintIOBuffer (ave_buffer, " (");
    271275  PrintIOBuffer (ave_buffer, OFF_T_FMT", ", average->extID);         
     
    288292  PRINT_FLOAT(ave_buffer, average->dD,       "%.5f, ");  // 0.010 mas precision
    289293
    290   // Add names.
    291   int ra_hr,ra_min,ra_sec,ra_fracsec;
    292   int dec_deg,dec_min,dec_sec,dec_fracsec;
    293   double tmp_ra,tmp_dec;
    294 
    295   if ((secfilt->NstackDet != 0)&&(isfinite(average->Rstk))&&(isfinite(average->Dstk))) {
    296     tmp_ra = average->Rstk;
    297     tmp_dec = average->Dstk;
    298   }
    299   else {
    300     tmp_ra = average->R;
    301     tmp_dec = average->D;
    302   }
    303  
    304   double dec_sign = (tmp_dec == 0.0) ? 0.0 : tmp_dec / fabs(tmp_dec);
    305   tmp_dec = fabs(tmp_dec);
    306 
    307 
    308   tmp_ra /= 15.0;
    309   ra_hr   = (int) floor(tmp_ra);
    310 
    311   tmp_ra -= ra_hr;
    312   tmp_ra *= 60.0;
    313   ra_min  = (int) floor(tmp_ra);
    314  
    315   tmp_ra -= ra_min;
    316   tmp_ra *= 60.0;
    317   ra_sec  = (int) floor(tmp_ra);
    318 
    319   tmp_ra -= ra_sec;
    320   tmp_ra *= 1000.0;
    321   ra_fracsec = (int) floor(tmp_ra);
    322 
    323   dec_deg = (int) floor(tmp_dec);
    324 
    325   tmp_dec -= dec_deg;
    326   tmp_dec *= 60.0;
    327   dec_min = (int) floor(tmp_dec);
    328 
    329   tmp_dec -= dec_min;
    330   tmp_dec *= 60.0;
    331   dec_sec = (int) floor(tmp_dec);
    332 
    333   tmp_dec -= dec_sec;
    334   tmp_dec *= 1000.0;
    335   dec_fracsec = (int) floor(tmp_dec);
    336 
    337   dec_deg *= (int) dec_sign;
    338 
    339   // IAU NAME
    340   PrintIOBuffer(ave_buffer, "'PSO J%02d%02d%02d.%03d%+03d%02d%02d.%03d',  ",
    341                 ra_hr,ra_min,ra_sec,ra_fracsec,
    342                 dec_deg,dec_min,dec_sec,dec_fracsec);
    343 
    344   // PSO NAME
    345   if ((secfilt->NstackDet != 0)&&(isfinite(average->Rstk))&&(isfinite(average->Dstk))) {
    346     tmp_ra = average->Rstk;
    347     tmp_dec = average->Dstk;
    348   }
    349   else {
    350     tmp_ra = average->R;
    351     tmp_dec = average->D;
    352   }
    353 
    354   PrintIOBuffer(ave_buffer, "'PSO J%09.5f%+09.5f',  ",
    355                 tmp_ra,tmp_dec);
     294  int useStack = (!isfinite(average->R) || !isfinite(average->D)) && (secfilt->NstackDet != 0) && isfinite(average->Rstk) && isfinite(average->Dstk);
     295
     296  double tmp_ra  = useStack ? average->Rstk : average->R;
     297  double tmp_dec = useStack ? average->Dstk : average->D;
     298
     299  // PSO NAME (IAU approved)
     300  PrintIOBuffer(ave_buffer, "'PSO J%08.4f%+08.4f',  ", tmp_ra, tmp_dec);
     301
     302  // PSX NAME
     303  Format_PSX_Name (coord_buffer, 128, tmp_ra, tmp_dec);
     304  PrintIOBuffer(ave_buffer, "'%s',  ", coord_buffer);
    356305
    357306  // End names
     
    372321    float meanPSFMagMin = NAN;
    373322    float meanPSFMagMax = NAN;
    374     if (isfinite(secfilt->dM) && isfinite(secfilt->M)) {
    375       meanPSFMag    = secfilt->M;
    376       meanPSFMagErr = secfilt->dM;
    377       meanPSFMagStd = secfilt->Mstdev;
     323    if (isfinite(secfilt->dMpsfChp) && isfinite(secfilt->MpsfChp)) {
     324      meanPSFMag    = secfilt->MpsfChp;
     325      meanPSFMagErr = secfilt->dMpsfChp;
     326      meanPSFMagStd = secfilt->sMpsfChp;
    378327      meanPSFMagMin = secfilt->Mmin;
    379328      meanPSFMagMax = secfilt->Mmax;
     
    383332    float meanKronMagErr = NAN;
    384333    float meanKronMagStd = NAN;
    385     if (isfinite(secfilt->dMkron) && isfinite(secfilt->Mkron) && (secfilt->dMkron < 0.333)) {
    386       meanKronMag    = secfilt->Mkron;
    387       meanKronMagErr = secfilt->dMkron;
    388       meanKronMagStd = secfilt->sMkron;
     334    if (isfinite(secfilt->dMkronChp) && isfinite(secfilt->MkronChp) && (secfilt->dMkronChp < 0.333)) {
     335      meanKronMag    = secfilt->MkronChp;
     336      meanKronMagErr = secfilt->dMkronChp;
     337      meanKronMagStd = secfilt->sMkronChp;
    389338    }
    390339
     
    392341    float meanApMagErr = NAN;
    393342    float meanApMagStd = NAN;
    394     if (isfinite(secfilt->dMap) && isfinite(secfilt->Map)) {
    395       meanApMag    = secfilt->Map;
    396       meanApMagErr = secfilt->dMap;
    397       meanApMagStd = secfilt->sMap;
     343    if (isfinite(secfilt->dMapChp) && isfinite(secfilt->MapChp)) {
     344      meanApMag    = secfilt->MapChp;
     345      meanApMagErr = secfilt->dMapChp;
     346      meanApMagStd = secfilt->sMapChp;
    398347    }
    399348
     
    524473  return TRUE;
    525474}
     475
     476// XXX if the coords have NAN values (not sure why that would happen), return FALSE?
     477int Format_PSX_Name (char *buffer, int Nbuffer, double tmp_ra, double tmp_dec) {
     478
     479  // Add names.
     480  int ra_hr, ra_min, dec_deg, dec_min;
     481  float ra_sec, dec_sec;
     482
     483  // convert to hours:
     484  tmp_ra /= 15.0;
     485  ra_hr   = (int) floor(tmp_ra);
     486
     487  tmp_ra -= ra_hr;
     488  tmp_ra *= 60.0;
     489  ra_min  = (int) floor(tmp_ra);
     490 
     491  tmp_ra -= ra_min;
     492  tmp_ra *= 60.0;
     493  ra_sec = trunc(100.0*tmp_ra) / 100.0; // ensure truncation for XX.XX
     494
     495  char dec_sign = (tmp_dec >= 0.0) ? '+' : '-';
     496  tmp_dec = fabs(tmp_dec);
     497
     498  dec_deg = (int) floor(tmp_dec);
     499
     500  tmp_dec -= dec_deg;
     501  tmp_dec *= 60.0;
     502  dec_min = (int) floor(tmp_dec);
     503
     504  tmp_dec -= dec_min;
     505  tmp_dec *= 60.0;
     506  dec_sec = trunc(10.0*tmp_dec) / 10.0; // ensure truncation for XX.X
     507
     508  // PSX NAME
     509  snprintf (buffer, Nbuffer, "PSX J%02d%02d%05.2f%c%02d%02d%04.1f", ra_hr, ra_min, ra_sec, dec_sign, dec_deg, dec_min, dec_sec);
     510
     511  return TRUE;
     512}
  • trunk/Ohana/src/fakeastro/src/insert_fakestar.c

    r38469 r40291  
    9393
    9494    // I need a photcode for r-band
    95     catalog[0].secfilt[Nave*Nsecfilt+0].M = m_g;
    96     catalog[0].secfilt[Nave*Nsecfilt+1].M = m_r;
    97     catalog[0].secfilt[Nave*Nsecfilt+2].M = m_i;
    98     catalog[0].secfilt[Nave*Nsecfilt+3].M = m_z;
    99     catalog[0].secfilt[Nave*Nsecfilt+4].M = m_y;
     95    catalog[0].secfilt[Nave*Nsecfilt+0].MpsfChp = m_g;
     96    catalog[0].secfilt[Nave*Nsecfilt+1].MpsfChp = m_r;
     97    catalog[0].secfilt[Nave*Nsecfilt+2].MpsfChp = m_i;
     98    catalog[0].secfilt[Nave*Nsecfilt+3].MpsfChp = m_z;
     99    catalog[0].secfilt[Nave*Nsecfilt+4].MpsfChp = m_y;
    100100
    101101    catalog[0].starpar[Nstarpar]        = stars[i].starpar;
  • trunk/Ohana/src/fakeastro/src/load_template_images.c

    r38441 r40291  
    6161
    6262    refimage[Nrefimage].secz     = childImage->secz;
    63     refimage[Nrefimage].Mcal     = childImage->Mcal;
     63    refimage[Nrefimage].McalPSF  = childImage->McalPSF;
     64    refimage[Nrefimage].McalAPER = childImage->McalAPER;
    6465    refimage[Nrefimage].dMcal    = childImage->dMcal;
    6566    refimage[Nrefimage].exptime  = childImage->exptime;
  • trunk/Ohana/src/fakeastro/src/make_2mass_measures.c

    r39248 r40291  
    4444
    4545    // make a crude JHK color for now:
    46     double J_PS1 = secfilt[i*Nsecfilt + Nsec].M - 1.0; // make all stars have y-J = 1.0
     46    double J_PS1 = secfilt[i*Nsecfilt + Nsec].MpsfChp - 1.0; // make all stars have y-J = 1.0
    4747    if (J_PS1 > MAX_MAG_2MASS) continue; // only generate 2MASS detections for objects with J_PS1 < 16.0
    4848
    49     if (isnan(secfilt[i*Nsecfilt + Nsec].M)) {
     49    if (isnan(secfilt[i*Nsecfilt + Nsec].MpsfChp)) {
    5050      // look for a non-NAN secfilt mag and just use that (it is not super important)
    5151      int ns;
    5252      for (ns = 0; ns < Nsecfilt; ns++) {
    53         if (!isnan(secfilt[i*Nsecfilt + ns].M)) break;
     53        if (!isnan(secfilt[i*Nsecfilt + ns].MpsfChp)) break;
    5454      }
    5555      if (ns == Nsecfilt) continue; // no non-nan
    5656
    57       J_PS1 = secfilt[i*Nsecfilt + ns].M; // pretend secfilt.M = J
     57      J_PS1 = secfilt[i*Nsecfilt + ns].MpsfChp; // pretend secfilt.MpsfChp = J
    5858      if (J_PS1 > MAX_MAG_2MASS) continue; // only generate 2MASS detections for objects with J_PS1 < 16.0
    5959    }
     
    103103    measure[Nmeasure].airmass = 1.0;
    104104    measure[Nmeasure].az      = 0.0; // irrelevant
    105     measure[Nmeasure].Mcal    = 0.0;
     105    measure[Nmeasure].McalPSF = 0.0;
     106    measure[Nmeasure].McalAPER= 0.0;
    106107    measure[Nmeasure].t       = tzero_2mass;
    107108    measure[Nmeasure].dt      = 0.0;
  • trunk/Ohana/src/fakeastro/src/make_fake_stars_catalog.c

    r39926 r40291  
    4242
    4343  // XXX put in airmass?
    44   float ZP  = SCALE*code->C - image->Mcal + Mtime;
    45   float ZPo = 25.0 - image->Mcal + Mtime;
     44  float ZP  = SCALE*code->C - image->McalPSF + Mtime;
     45  float ZPo = 25.0 - image->McalPSF + Mtime;
    4646  // float ZP = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
    4747 
     
    7979    // float Minst = Msky - SCALE*code->C - measure[0].dt
    8080
    81     double Minst = secfilt[i*Nsecfilt + Nsec].M  - ZP;
     81    double Minst = secfilt[i*Nsecfilt + Nsec].MpsfChp - ZP;
    8282    double Counts = pow(10.0, -0.4*Minst);
    8383    double SkyCts = sky[Nsec];
     
    175175
    176176    stars[Nstars].measure.az      = azimuth (15.0*image->sidtime - stars[Nstars].average.R, stars[Nstars].average.D, image->latitude);
    177     stars[Nstars].measure.Mcal    = image->Mcal;
     177    stars[Nstars].measure.McalPSF = image->McalPSF;
     178    stars[Nstars].measure.McalAPER= image->McalAPER;
    178179    stars[Nstars].measure.t       = image->tzero + 1e-4*stars[Nstars].measure.Yccd*image->trate;  // trate is in 0.1 msec / row
    179180    stars[Nstars].measure.dt      = Mtime;
  • trunk/Ohana/src/fakeastro/src/make_gaia_measures.c

    r39926 r40291  
    4242
    4343    // make a crude G-i color for now:
    44     double G_PS1 = secfilt[i*Nsecfilt + Nsec].M; // make all stars have G-i = 1.0
     44    double G_PS1 = secfilt[i*Nsecfilt + Nsec].MpsfChp; // make all stars have G-i = 1.0
    4545    if (G_PS1 > MAX_MAG_GAIA) continue; // only generate GAIA detections for objects with G_PS1 < 21.0
    4646
    47     if (isnan(secfilt[i*Nsecfilt + Nsec].M)) {
     47    if (isnan(secfilt[i*Nsecfilt + Nsec].MpsfChp)) {
    4848      // look for a non-NAN secfilt mag and just use that (it is not super important)
    4949      int ns;
    5050      for (ns = 0; ns < Nsecfilt; ns++) {
    51         if (!isnan(secfilt[i*Nsecfilt + ns].M)) break;
     51        if (!isnan(secfilt[i*Nsecfilt + ns].MpsfChp)) break;
    5252      }
    5353      if (ns == Nsecfilt) continue; // no non-nan
    5454
    55       G_PS1 = secfilt[i*Nsecfilt + ns].M; // pretend secfilt.M = G
     55      G_PS1 = secfilt[i*Nsecfilt + ns].MpsfChp; // pretend secfilt.M = G
    5656      if (G_PS1 > MAX_MAG_GAIA) continue; // only generate GAIA detections for objects with G_PS1 < 21.0
    5757    }
     
    104104    measure[Nmeasure].airmass = 1.0;
    105105    measure[Nmeasure].az      = 0.0; // irrelevant
    106     measure[Nmeasure].Mcal    = 0.0;
     106    measure[Nmeasure].McalPSF = 0.0;
     107    measure[Nmeasure].McalAPER= 0.0;
    107108    measure[Nmeasure].t       = tzero_gaia;
    108109    measure[Nmeasure].dt      = 0.0;
  • trunk/Ohana/src/getstar/src/ReadImageHeader.c

    r39998 r40291  
    127127
    128128  /* secz is in units milli-airmass */
    129   image[0].Mcal = 0.0;
    130   image[0].Xm   = NAN_S_SHORT;
     129  image[0].McalPSF   = 0.0;
     130  image[0].McalAPER  = 0.0;
     131  image[0].McalChiSq = NAN;
    131132  image[0].flags = 0;
    132133
  • trunk/Ohana/src/getstar/src/select_by_region.c

    r38441 r40291  
    7878        }
    7979      } else {
    80         mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
     80        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].MpsfChp;
    8181      }
    8282      if (isnan(mag)) continue;
     
    131131        }
    132132      } else {
    133         mag = catalog[0].secfilt[i*Nsecfilt + Nsec].M;
     133        mag = catalog[0].secfilt[i*Nsecfilt + Nsec].MpsfChp;
    134134      }
    135135      if (isnan(mag) || (mag > MagLimitValue)) continue;
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r38441 r40291  
    5555    // find primary magnitude
    5656    if (Nsec_c0 != -1) {
    57       output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].M;
     57      output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].MpsfChp;
    5858    } else {
    5959      output[i].mag = NAN;
     
    6969    // find color term 1
    7070    if (Nsec_c1 != -1) {
    71       output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
     71      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].MpsfChp;
    7272    } else {
    7373      output[i].c1 = NAN;
     
    8383    // find color term 2
    8484    if (Nsec_c2 != -1) {
    85       output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
     85      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].MpsfChp;
    8686    } else {
    8787      output[i].c2 = NAN;
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r38441 r40291  
    5858    // find primary magnitude
    5959    if (Nsec_c0 != -1) {
    60       output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].M;
     60      output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].MpsfChp;
    6161    } else {
    6262      output[i].mag = NAN;
     
    7272    // find color term 1
    7373    if (Nsec_c1 != -1) {
    74       output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
     74      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].MpsfChp;
    7575    } else {
    7676      output[i].c1 = NAN;
     
    8686    // find color term 2
    8787    if (Nsec_c2 != -1) {
    88       output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
     88      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].MpsfChp;
    8989    } else {
    9090      output[i].c2 = NAN;
  • trunk/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r38441 r40291  
    6464    // find primary magnitude
    6565    if (Nsec_c0 != -1) {
    66       output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].M;
     66      output[i].mag = secfilt[i*Nsecfilt + Nsec_c0].MpsfChp;
    6767    } else {
    6868      output[i].mag = NAN;
     
    7878    // find color term 1
    7979    if (Nsec_c1 != -1) {
    80       output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].M;
     80      output[i].c1 = secfilt[i*Nsecfilt + Nsec_c1].MpsfChp;
    8181    } else {
    8282      output[i].c1 = NAN;
     
    9292    // find color term 2
    9393    if (Nsec_c2 != -1) {
    94       output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].M;
     94      output[i].c2 = secfilt[i*Nsecfilt + Nsec_c2].MpsfChp;
    9595    } else {
    9696      output[i].c2 = NAN;
  • trunk/Ohana/src/imregister/imphot/dumpfits.c

    r38441 r40291  
    114114    startstr = ohana_sec_to_date (subset[0].tzero);
    115115    filtstr  = GetPhotcodeNamebyCode (subset[0].photcode);
    116     zp       = subset[0].Mcal;
     116    zp       = subset[0].McalPSF;
    117117    dzp      = subset[0].dMcal;
    118118    XY_to_RD (&ra, &dec, 0.0, 0.0, &subset[0].coords);
  • trunk/Ohana/src/imregister/imphot/output.c

    r34088 r40291  
    3737     
    3838    fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr,
    39              image[i].Mcal, image[i].dMcal, image[i].secz, image[i].nstar, image[i].flags);
     39             image[i].McalPSF, image[i].dMcal, image[i].secz, image[i].nstar, image[i].flags);
    4040    free (timestr);
    4141  }
  • trunk/Ohana/src/kapa2/src/DrawObjects.c

    r40165 r40291  
    9797  switch (object[0].style) {
    9898    case KAPA_PLOT_CONNECT:
     99      // fprintf (stderr, "plot KAPA_PLOT_CONNECT: \n");
    99100      DrawConnect (graphic, graph, object);
    100101      break;
    101102    case KAPA_PLOT_HISTOGRAM:
     103      // fprintf (stderr, "plot KAPA_PLOT_HISTOGRAM:\n");
    102104      DrawHistogram (graphic, graph, object);
    103105      break;
    104106    case KAPA_PLOT_BARS_SOLID:
     107      // fprintf (stderr, "plot KAPA_PLOT_BARS_SOLID:\n");
    105108      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_SOLID);
    106109      break;
    107110    case KAPA_PLOT_BARS_OUTLINE:
     111      // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTLINE:\n");
    108112      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTLINE);
    109113      break;
    110114    case KAPA_PLOT_BARS_OUTFILL:
     115      // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTFILL:\n");
    111116      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTFILL);
    112117      break;
    113118    case KAPA_PLOT_POINTS:
    114119    default:
     120      // fprintf (stderr, "plot KAPA_PLOT_POINTS:\n");
    115121      DrawPoints (graphic, graph, object);
    116122      break;
  • trunk/Ohana/src/libautocode/Makefile.Targets

    r40062 r40291  
    1414$(ASRC)/average-ps1-v4.$(ARCH).o \
    1515$(ASRC)/average-ps1-v5.$(ARCH).o \
     16$(ASRC)/average-ps1-v6.$(ARCH).o \
    1617$(ASRC)/average-ps1-v5-ld.$(ARCH).o \
    1718$(ASRC)/average-ps1-sim.$(ARCH).o \
     
    2930$(ASRC)/secfilt-ps1-v4.$(ARCH).o \
    3031$(ASRC)/secfilt-ps1-v5.$(ARCH).o \
     32$(ASRC)/secfilt-ps1-v6.$(ARCH).o \
    3133$(ASRC)/secfilt-ps1-v5-ld.$(ARCH).o \
    3234$(ASRC)/secfilt-ps1-sim.$(ARCH).o \
     
    4446$(ASRC)/measure-ps1-v4.$(ARCH).o \
    4547$(ASRC)/measure-ps1-v5.$(ARCH).o \
     48$(ASRC)/measure-ps1-v6.$(ARCH).o \
    4649$(ASRC)/measure-ps1-v5-ld.$(ARCH).o \
    4750$(ASRC)/measure-ps1-sim.$(ARCH).o \
     
    5356$(ASRC)/lensing-ps1-v5-r3.$(ARCH).o \
    5457$(ASRC)/lensing-ps1-v5-ld.$(ARCH).o \
     58$(ASRC)/lensing-ps1-v6.$(ARCH).o \
    5559$(ASRC)/lensobj.$(ARCH).o \
    5660$(ASRC)/lensobj-ps1-v5-r0.$(ARCH).o \
    5761$(ASRC)/lensobj-ps1-v5-r1.$(ARCH).o \
    5862$(ASRC)/lensobj-ps1-v5-ld.$(ARCH).o \
     63$(ASRC)/lensobj-ps1-v6.$(ARCH).o \
    5964$(ASRC)/starpar.$(ARCH).o \
    6065$(ASRC)/starpar-ps1-v5.$(ARCH).o \
     66$(ASRC)/starpar-ps1-v6.$(ARCH).o \
    6167$(ASRC)/starpar-ps1-v5-ld.$(ARCH).o \
    6268$(ASRC)/starpar-ps1-sim.$(ARCH).o \
     
    6571$(ASRC)/galphot-ps1-v5-r1.$(ARCH).o \
    6672$(ASRC)/galphot-ps1-v5-ld.$(ARCH).o \
     73$(ASRC)/galphot-ps1-v6.$(ARCH).o \
    6774$(ASRC)/missing.$(ARCH).o \
    6875$(ASRC)/photcode.$(ARCH).o \
     
    7683$(ASRC)/photcode-ps1-v4.$(ARCH).o \
    7784$(ASRC)/photcode-ps1-v5.$(ARCH).o \
     85$(ASRC)/photcode-ps1-v6.$(ARCH).o \
    7886$(ASRC)/photcode-ps1-v5-ld.$(ARCH).o \
    7987$(ASRC)/photcode-ps1-ref.$(ARCH).o \
     
    9098$(ASRC)/image-ps1-v4.$(ARCH).o \
    9199$(ASRC)/image-ps1-v5.$(ARCH).o \
     100$(ASRC)/image-ps1-v6.$(ARCH).o \
    92101$(ASRC)/image-ps1-v5-ld.$(ARCH).o \
    93102$(ASRC)/image-ps1-sim.$(ARCH).o \
     
    136145$(AINC)/average-ps1-v4.h \
    137146$(AINC)/average-ps1-v5.h \
     147$(AINC)/average-ps1-v6.h \
    138148$(AINC)/average-ps1-v5-ld.h \
    139149$(AINC)/average-ps1-sim.h \
     
    151161$(AINC)/secfilt-ps1-v4.h \
    152162$(AINC)/secfilt-ps1-v5.h \
     163$(AINC)/secfilt-ps1-v6.h \
    153164$(AINC)/secfilt-ps1-v5-ld.h \
    154165$(AINC)/secfilt-ps1-sim.h \
     
    166177$(AINC)/measure-ps1-v4.h \
    167178$(AINC)/measure-ps1-v5.h \
     179$(AINC)/measure-ps1-v6.h \
    168180$(AINC)/measure-ps1-v5-ld.h \
    169181$(AINC)/measure-ps1-sim.h \
     
    175187$(AINC)/lensing-ps1-v5-r3.h \
    176188$(AINC)/lensing-ps1-v5-ld.h \
     189$(AINC)/lensing-ps1-v6.h \
    177190$(AINC)/lensobj.h \
    178191$(AINC)/lensobj-ps1-v5-r0.h \
    179192$(AINC)/lensobj-ps1-v5-r1.h \
    180193$(AINC)/lensobj-ps1-v5-ld.h \
     194$(AINC)/lensobj-ps1-v6.h \
    181195$(AINC)/starpar.h \
    182196$(AINC)/starpar-ps1-v5.h \
     197$(AINC)/starpar-ps1-v6.h \
    183198$(AINC)/starpar-ps1-v5-ld.h \
    184199$(AINC)/starpar-ps1-sim.h \
     
    187202$(AINC)/galphot-ps1-v5-r1.h \
    188203$(AINC)/galphot-ps1-v5-ld.h \
     204$(AINC)/galphot-ps1-v6.h \
    189205$(AINC)/missing.h \
    190206$(AINC)/photcode.h \
     
    198214$(AINC)/photcode-ps1-v4.h \
    199215$(AINC)/photcode-ps1-v5.h \
     216$(AINC)/photcode-ps1-v6.h \
    200217$(AINC)/photcode-ps1-v5-ld.h \
    201218$(AINC)/photcode-ps1-ref.h \
     
    212229$(AINC)/image-ps1-v4.h \
    213230$(AINC)/image-ps1-v5.h \
     231$(AINC)/image-ps1-v6.h \
    214232$(AINC)/image-ps1-v5-ld.h \
    215233$(AINC)/image-ps1-sim.h \
  • trunk/Ohana/src/libautocode/def/image.d

    r37807 r40291  
    22EXTNAME      DVO_IMAGE
    33TYPE         BINTABLE
    4 SIZE         384
     4SIZE         392
    55DESCRIPTION  DVO Image Table
     6
     7## XXX NOTE: as of 2015.01.11 (r 37807), I had to move this structure from the autocode
     8## version to libdvo/include/libdvo_astro.h to support self-references
    69
    710# elements of the image structure
     
    3538FIELD     apmifit,          APMIFIT,              float,          aperture correction,       mag
    3639FIELD     dapmifit,         DAPMIFIT,             float,          apmifit error,             mag
    37 FIELD     Mcal,             MCAL,                 float,          calibration mag,           mag
     40FIELD     McalPSF,          MCAL_PSF,             float,          calibration mag for PSF, mag
     41FIELD     McalAPER,         MCAL_APER,            float,          calibration mag for Aperture, mag
    3842FIELD     dMcal,            DMCAL,                float,          error on Mcal,             mag
    39 FIELD     Xm,               XM,                   short,          image chisq,               10*log(value)
     43FIELD     McalChiSq,        XM,                   float,          image chisq
     44FIELD     padding_1,        PADDING,              short,          identifier for CCD,
    4045FIELD     photcode,         PHOTCODE,             short,          identifier for CCD,
    4146FIELD     exptime,          EXPTIME,              float,          exposure time,             seconds
    4247FIELD     sidtime,          ST,                   float,          sidereal time of exposure
    4348FIELD     latitude,         LAT,                  float,          observatory latitude,      degrees
    44 # 40 bytes
     49# 56 bytes
    4550
    4651FIELD     RAo,              RA_CENTER,            float,          image center,              degrees
  • trunk/Ohana/src/libautocode/def/measure.d

    r39262 r40291  
    1313FIELD Mkron,          M_KRON,        float,          kron magnitude,                 mag
    1414FIELD dMkron,         M_KRON_ERR,    float,          kron magnitude error,           mag
    15 FIELD Mcal,           M_CAL,         float,          image cal mag,                  mag
     15FIELD McalPSF,        MCAL_PSF,      float,          image cal mag,                  mag
    1616FIELD dMcal,          MAG_CAL_ERR,   float,          systematic calibration error,   mag
    1717FIELD dt,             M_TIME,        float,          exposure time,                  2.5*log(exptime)
     
    4444
    4545FIELD Mflat,          M_FLAT,        float,          Static Flat-field offset,     mag
    46 FIELD dummy2,         PADDING,       int,            unused 4 bytes
     46FIELD McalAPER,       MCAL_APER,     float,          image cal mag for apertures,  mag
    4747
    4848# could these be packed into fewer bits?
     
    5353FIELD averef,         AVE_REF,      unsigned int,   reference to average entry     
    5454
     55# internally, this is an unsigned int; however, we do NOT convert with TZERO/TSCAL on output
    5556FIELD detID,          DET_ID,       unsigned int,   detection ID
    5657FIELD objID,          OBJ_ID,       unsigned int,   unique ID for object in table
    5758FIELD catID,          CAT_ID,       unsigned int,   unique ID for table in which object was first realized
    5859
     60# extID needs to be on an 8-byte boundary
    5961# PSPS uses a 64-bit detection ID
    6062FIELD extID,          EXT_ID,       uint64_t,       external ID (eg PSPS detID)
     
    9193FIELD dRsys,          POS_SYS_ERR,  short,          systematic error from astrom,   1/100 of pixels
    9294
     95# local astrometry scales
    9396FIELD posangle,       POSANGLE,     short,          position angle sky to chip,     (0xffff/360) deg
    9497FIELD pltscale,       PLTSCALE,     float,          plate scale,                    arcsec/pixel
  • trunk/Ohana/src/libautocode/def/secfilt.d

    r37246 r40291  
    55DESCRIPTION  DVO SecFilt : Secondary Filter Data
    66
     7## 2017.11.22 : To clarify the parallel structures, I am explicitly renaming M,Map,Mkron to MpsfChp, MapChp, MkronChp
     8
    79## *** this section is for per-exposure mean values *** (unlabled values are implicitly PSF values)
    8 FIELD  M,             MAG,             float,      average mag in this band,              mags
    9 FIELD  dM,            MAG_ERR,         float,      formal error on average mag,           mags
    10 FIELD  Map,           MAG_AP,          float,      average mag in this band,              mags
    11 FIELD  dMap,          MAG_AP_ERR,      float,      formal error on average mag,           mags
    12 FIELD  sMap,          MAG_AP_STDEV,    float,      standard deviation of ap mags,         mags
    13 FIELD  Mkron,         MAG_KRON,        float,      ave kron mag in this band,             mags
    14 FIELD  dMkron,        MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
    15 FIELD  sMkron,        MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
     10FIELD  MpsfChp,       MAG,             float,      average mag in this band,              mags
     11FIELD  dMpsfChp,      MAG_ERR,         float,      formal error on average mag,           mags
     12FIELD  sMpsfChp,      MAG_STDEV,       float,      standard deviation of measurements,    mags
     13
     14FIELD  MapChp,        MAG_AP,          float,      average mag in this band,              mags
     15FIELD  dMapChp,       MAG_AP_ERR,      float,      formal error on average mag,           mags
     16FIELD  sMapChp,       MAG_AP_STDEV,    float,      standard deviation of ap mags,         mags
     17
     18FIELD   MkronChp,     MAG_KRON,        float,      ave kron mag in this band,             mags
     19FIELD  dMkronChp,     MAG_KRON_ERR,    float,      formal error on average kron mag,      mags
     20FIELD  sMkronChp,     MAG_KRON_STDEV,  float,      standard deviation of kron mags,       mags
    1621
    1722# XXX I could add these fields to secfilt or calculate in dvopsps?
     
    2025
    2126# these statistics are PSF-specific     
    22 FIELD  Mstdev,        MAG_STDEV,       float,      standard deviation of measurements,    mags
    2327FIELD  Mmin,          MAG_MIN,         float,      minimum accepted mag,                  mags
    2428FIELD  Mmax,          MAG_MAX,         float,      maximum accepted mag,                  mags
  • trunk/Ohana/src/libdvo/Makefile

    r40063 r40291  
    5050$(DESTINC)/ps1_v4_defs.h \
    5151$(DESTINC)/ps1_v5_defs.h \
     52$(DESTINC)/ps1_v6_defs.h \
    5253$(DESTINC)/ps1_v5_ld_defs.h \
    5354$(DESTINC)/ps1_ref_defs.h \
     
    100101$(SRC)/dvo_convert_PS1_V4.$(ARCH).o \
    101102$(SRC)/dvo_convert_PS1_V5.$(ARCH).o \
     103$(SRC)/dvo_convert_PS1_V6.$(ARCH).o \
    102104$(SRC)/dvo_convert_PS1_V5_LOAD.$(ARCH).o \
    103105$(SRC)/dvo_convert_PS1_REF.$(ARCH).o \
  • trunk/Ohana/src/libdvo/doc/notes.txt

    r34749 r40291  
    1616   uppercase, eg: AveragePanstarrs_DEV_0, AveragePanstarrs_PS1_2).
    1717
    18 4) create a DVOTableFormat entry for the new format
     184) create a DVOCatFormat entry for the new format
    1919   (libdvo/include/dvo.h).  the naming convention is DVO_FORMAT_FOO.
    2020
     
    3737   make is easy to identify the new changes needed.
    3838
    39 10) add the new format to the section at the end of dvo_image.c
     3910a) if the Image structure must be changed, this is done in libdvo/include/libdvo_astro.h, not autocode
     4010b) add the new format to the section at the end of dvo_image.c
     4110c) update gfits_table_mkheader_Image in dvo_image.c to match modifications to Image (if any)
    4042
    414311) add the new format to the dvo_image_raw.c
  • trunk/Ohana/src/libdvo/include/dvo.h

    r40063 r40291  
    3333  DVO_FORMAT_PS1_V4,
    3434  DVO_FORMAT_PS1_V5,
     35  DVO_FORMAT_PS1_V6,
    3536  DVO_FORMAT_PS1_V5_LOAD,
    3637} DVOCatFormat;
     
    220221/* Secfilt.flags values -- these values are 32 bit (as of PS1_V1) */
    221222typedef enum {
    222   ID_SECF_STAR_FEW      = 0x00000001, // used within relphot: skip star
    223   ID_SECF_STAR_POOR     = 0x00000002, // used within relphot: skip star
    224   ID_SECF_USE_SYNTH     = 0x00000004, // synthetic photometry used in average measurement
    225   ID_SECF_USE_UBERCAL   = 0x00000008, // ubercal photometry used in average measurement
    226   ID_SECF_HAS_PS1       = 0x00000010, // PS1 photometry used in average measurement
    227   ID_SECF_HAS_PS1_STACK = 0x00000020, // PS1 stack photometry exists
    228   ID_SECF_HAS_TYCHO     = 0x00000040, // Tycho photometry used for synth mags
    229   ID_SECF_FIX_SYNTH     = 0x00000080, // synth mags repaired with zpt map
    230   ID_SECF_RANK_0        = 0x00000100, // average magnitude uses rank 0 values
    231   ID_SECF_RANK_1        = 0x00000200, // average magnitude uses rank 1 values
    232   ID_SECF_RANK_2        = 0x00000400, // average magnitude uses rank 2 values
    233   ID_SECF_RANK_3        = 0x00000800, // average magnitude uses rank 3 values
    234   ID_SECF_RANK_4        = 0x00001000, // average magnitude uses rank 4 values
    235   ID_SECF_OBJ_EXT_PSPS  = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
    236   ID_SECF_STACK_PRIMARY = 0x00004000, // PS1 stack photometry comes from primary skycell
    237   ID_SECF_STACK_BESTDET = 0x00008000, // PS1 stack best measurement is a detection (not forced)
    238   ID_SECF_STACK_PRIMDET = 0x00010000, // PS1 stack primary measurement is a detection (not forced)
    239 
    240   ID_SECF_HAS_SDSS      = 0x00100000, // this photcode has SDSS photometry
    241   ID_SECF_HAS_HSC       = 0x00200000, // this photcode has HSC  photometry
    242   ID_SECF_HAS_CFH       = 0x00400000, // this photcode has CFH  photometry (mostly Megacam)
    243   ID_SECF_HAS_DES       = 0x00800000, // this photcode has DES  photometry
    244 
    245   ID_SECF_OBJ_EXT       = 0x01000000, // extended in this band
    246 
    247   ID_SECF_CHIP_FLAGS    = 0x01003f1f, // all chip-related bits (used to reset the correct bits only)
    248   ID_SECF_STACK_FLAGS   = 0x00004020, // all stack-related bits (
     223  ID_SECF_STAR_FEW               = 0x00000001, // used within relphot: skip star
     224  ID_SECF_STAR_POOR              = 0x00000002, // used within relphot: skip star
     225  ID_SECF_USE_SYNTH              = 0x00000004, // synthetic photometry used in average measurement
     226  ID_SECF_USE_UBERCAL            = 0x00000008, // ubercal photometry used in average measurement
     227  ID_SECF_HAS_PS1                = 0x00000010, // PS1 photometry used in average measurement
     228  ID_SECF_HAS_PS1_STACK          = 0x00000020, // PS1 stack photometry exists
     229  ID_SECF_HAS_TYCHO              = 0x00000040, // Tycho photometry used for synth mags
     230  ID_SECF_FIX_SYNTH              = 0x00000080, // synth mags repaired with zpt map
     231  ID_SECF_RANK_0                 = 0x00000100, // average magnitude uses rank 0 values
     232  ID_SECF_RANK_1                 = 0x00000200, // average magnitude uses rank 1 values
     233  ID_SECF_RANK_2                 = 0x00000400, // average magnitude uses rank 2 values
     234  ID_SECF_RANK_3                 = 0x00000800, // average magnitude uses rank 3 values
     235  ID_SECF_RANK_4                 = 0x00001000, // average magnitude uses rank 4 values
     236  ID_SECF_OBJ_EXT_PSPS           = 0x00002000, // In PSPS ID_SECF_OBJ_EXT is moved here so it fits within 16 bits
     237  ID_SECF_STACK_PRIMARY          = 0x00004000, // PS1 stack photometry includes a primary skycell
     238  ID_SECF_STACK_BESTDET          = 0x00008000, // PS1 stack best measurement is a detection (not forced)
     239  ID_SECF_STACK_PRIMDET          = 0x00010000, // PS1 stack primary measurement is a detection (not forced)
     240  ID_SECF_STACK_PRIMARY_MULTIPLE = 0x00020000, // PS1 stack object has multiple primary measurements
     241
     242  ID_SECF_HAS_SDSS               = 0x00100000, // this photcode has SDSS photometry
     243  ID_SECF_HAS_HSC                = 0x00200000, // this photcode has HSC  photometry
     244  ID_SECF_HAS_CFH                = 0x00400000, // this photcode has CFH  photometry (mostly Megacam)
     245  ID_SECF_HAS_DES                = 0x00800000, // this photcode has DES  photometry
     246
     247  ID_SECF_OBJ_EXT                = 0x01000000, // extended in this band
     248
     249  ID_SECF_CHIP_FLAGS             = 0x01003f1f, // all chip-related bits (used to reset the correct bits only)
     250  ID_SECF_STACK_FLAGS            = 0x0003c020, // all stack-related bits (
    249251} DVOSecfiltFlags;
    250252
     
    501503  double         R;
    502504  double         D;
    503   float          M;
    504   float          Mcal;
     505  float          M; // change to Mpsf eventually to disambiguate
     506  float          Mkron;
     507  float          McalPSF;
     508  float          McalAPER;
    505509  float          Mflat;
    506510  float          dM;
     
    10731077# include "ps1_v4_defs.h"
    10741078# include "ps1_v5_defs.h"
     1079# include "ps1_v6_defs.h"
    10751080# include "ps1_v5_ld_defs.h"
    10761081# include "ps1_ref_defs.h"
  • trunk/Ohana/src/libdvo/include/dvodb.h

    r39633 r40291  
    33
    44# define MEASURE_HAS_XCCD 1
     5
     6// Some values used by code moved to libdvo from opihi.
     7enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT};
     8# define opihi_flt double
     9// # define opihi_int int64_t
     10# define opihi_int long long int
     11# define OPIHI_INT_FMT "%lld"
    512
    613typedef enum {
     
    236243      MEAS_EXTERN_ID,
    237244      MEAS_EXPNAME_AS_INT,
    238       MEAS_MCAL_OFFSET, // make this a dvoMagOption?
     245      MEAS_MCAL_OFFSET_PSF, // make this a dvoMagOption?
     246      MEAS_MCAL_OFFSET_APER, // make this a dvoMagOption?
    239247      MEAS_FLAT,
    240248      MEAS_CENTER_OFFSET,
     
    369377      IMAGE_XM,
    370378      IMAGE_AIRMASS,
    371       IMAGE_MCAL,
     379      IMAGE_MCAL_PSF,
     380      IMAGE_MCAL_APER,
    372381      IMAGE_dMCAL,
    373382      IMAGE_PHOTCODE,
     
    471480  char    type;
    472481  int     field;
    473   // opihi_flt FltValue;
    474   // opihi_int IntValue;
    475   double FltValue;
    476   int IntValue;
     482  opihi_flt FltValue;
     483  opihi_int IntValue;
     484  // double FltValue;
     485  // int IntValue;
    477486} dbStack;
    478487
    479488typedef struct {
    480   // opihi_flt Flt;
    481   // opihi_int Int;
    482   double Flt;
    483   int Int;
     489  opihi_flt Flt;
     490  opihi_int Int;
     491  // double Flt;
     492  // int Int;
    484493} dbValue;
    485494
     
    562571int dbExtractImagesReset (void);
    563572
    564 // Some values used by code moved to libdvo from opihi.
    565 enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT};
    566 #define opihi_flt double
    567 #define opihi_int int
    568 
    569573#include "get_graphdata.h"
    570574
  • trunk/Ohana/src/libdvo/include/libdvo_astro.h

    r39457 r40291  
    100100  float            apmifit;              // aperture correction (mag)
    101101  float            dapmifit;             // apmifit error (mag)
    102   float            Mcal;                 // calibration mag (mag)
     102  float            McalPSF;              // calibration mag (mag)
     103  float            McalAPER;             // calibration mag (mag)
    103104  float            dMcal;                // error on Mcal (mag)
    104   short            Xm;                   // image chisq (10*log(value))
     105  float            McalChiSq;            // image chisq (10*log(value))
    105106  short            photcode;             // identifier for CCD,
    106107  float            exptime;              // exposure time (seconds)
  • trunk/Ohana/src/libdvo/src/ImageMetadata.c

    r37807 r40291  
    6464  GET_COLUMN (crval2,   "CRVAL2",         double);
    6565  GET_COLUMN (theta,    "THETA",          float);
    66   GET_COLUMN (Mcal,     "MCAL",           float);
     66  GET_COLUMN (McalPSF,  "MCAL",           float);
    6767  GET_COLUMN (secz,     "SECZ",           float);
    6868  GET_COLUMN (Xcenter,  "X_CENTER",       float);
     
    7777    image[i].crval2   = crval2[i]  ;
    7878    image[i].theta    = theta[i]  ;
    79     image[i].Mcal     = Mcal[i]    ;
     79    image[i].Mcal     = McalPSF[i]    ;
    8080    image[i].secz     = secz[i]    ;
    8181    image[i].Xcenter  = Xcenter[i] ;
     
    9090  free (crval2);
    9191  free (theta);
    92   free (Mcal);
     92  free (McalPSF);
    9393  free (secz);
    9494  free (Xcenter);
     
    166166    theta[i]    = DEG_RAD*atan2(mosaic->pc1_2, mosaic->pc1_1);
    167167
    168     Mcal[i]     = image[i].Mcal;
     168    Mcal[i]     = image[i].McalPSF;
    169169    secz[i]     = image[i].secz;
    170170    Xcenter[i]  = 0.5*image[i].NX;
  • trunk/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r40063 r40291  
    6464  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V4",      PS1_V4);
    6565  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V5",      PS1_V5);
     66  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V6",      PS1_V6);
    6667  CONVERT_FORMAT("DVO_PHOTCODE_PS1_V5_LOAD", PS1_V5_LOAD);
    6768
  • trunk/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r38553 r40291  
    3030  // for the moment, we simply support the latest photcode format for output
    3131  // XXX update this as needed as new formats are defined
    32   PhotCode_PS1_V5 *photcode_output = PhotCode_Internal_To_PS1_V5 (table[0].code, table[0].Ncode);
     32  PhotCode_PS1_V6 *photcode_output = PhotCode_Internal_To_PS1_V6 (table[0].code, table[0].Ncode);
    3333
    3434  /* convert FITS format data to internal format (byteswaps & EXTNAME) */
    3535  if (!gfits_db_create (&db)) return (FALSE);
    36   if (!gfits_table_set_PhotCode_PS1_V5 (&db.ftable, photcode_output, table[0].Ncode, TRUE)) return (FALSE);
     36  if (!gfits_table_set_PhotCode_PS1_V6 (&db.ftable, photcode_output, table[0].Ncode, TRUE)) return (FALSE);
    3737  if (!gfits_db_save (&db)) return (FALSE);
    3838  if (!gfits_db_close (&db)) return (FALSE);
  • trunk/Ohana/src/libdvo/src/dbCheckStack.c

    r39578 r40291  
    4343       * an int unless proven otherwise **/
    4444      stack[i].FltValue = strtod (stack[i].name, &c1);
    45       stack[i].IntValue = strtol (stack[i].name, &c2, 0);
     45      stack[i].IntValue = strtoll (stack[i].name, &c2, 0);
    4646      if (c2 == stack[i].name + strlen (stack[i].name)) {
    4747        stack[i].type  |= DB_STACK_INT;
  • trunk/Ohana/src/libdvo/src/dbExtractImages.c

    r39457 r40291  
    219219      break;
    220220
    221     case IMAGE_MCAL:
    222       value.Flt = image[N].Mcal;
     221    case IMAGE_MCAL_PSF:
     222      value.Flt = image[N].McalPSF;
     223      break;
     224    case IMAGE_MCAL_APER:
     225      value.Flt = image[N].McalAPER;
    223226      break;
    224227    case IMAGE_dMCAL:
     
    226229      break;
    227230    case IMAGE_XM:
    228       value.Flt = pow(10.0, 0.01*image[N].Xm);
     231      value.Flt = image[N].McalChiSq;
    229232      break;
    230233    case IMAGE_PHOTCODE:
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r39926 r40291  
    740740      break;
    741741
    742     case MEAS_MCAL_OFFSET: { value.Flt = measure[0].Mcal; break; }
     742    case MEAS_MCAL_OFFSET_PSF:  { value.Flt = measure[0].McalPSF;  break; }
     743    case MEAS_MCAL_OFFSET_APER: { value.Flt = measure[0].McalAPER; break; }
    743744    case MEAS_FLAT: { value.Flt = measure[0].Mflat; break; }
    744745
  • trunk/Ohana/src/libdvo/src/dbFields.c

    r39633 r40291  
    333333
    334334  // make a local working copy of fieldName and replace ':' with spaces
     335  // XXX memory leak here:
    335336  char *fieldCopy = strcreate(fieldName);
    336337  for (j = 0; fieldCopy[j]; j++) {
     
    338339  }
    339340
     341  // XXX potential memory leak here
    340342  char *firstWord = getword(fieldCopy);
     343  if (!firstWord) return FALSE;
    341344 
    342345  // firstWord may be either flux, mag or photcode
     
    606609  if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            OPIHI_FLT);
    607610  if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           OPIHI_FLT);
    608   if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    OPIHI_FLT);
     611  if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET_PSF,    OPIHI_FLT);
     612  if (!strcasecmp (fieldName, "MCAL_OFFSET_PSF"))  ESCAPE (MEAS_MCAL_OFFSET_PSF,  OPIHI_FLT);
     613  if (!strcasecmp (fieldName, "MCAL_OFFSET_APER")) ESCAPE (MEAS_MCAL_OFFSET_APER, OPIHI_FLT);
    609614  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
    610615  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
     
    842847  if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  OPIHI_FLT);
    843848
    844   if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      OPIHI_FLT);
    845   if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     OPIHI_FLT);
    846   if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        OPIHI_FLT);
    847   if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  OPIHI_INT);
    848   if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   OPIHI_FLT);
    849   if (!strcasecmp (fieldName, "expname"  )) ESCAPE (IMAGE_EXPNAME_AS_INT, OPIHI_INT);
    850   if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   OPIHI_FLT);
     849  if (!strcasecmp (fieldName, "Mcal"        )) ESCAPE (IMAGE_MCAL_PSF,       OPIHI_FLT);
     850  if (!strcasecmp (fieldName, "McalPSF"     )) ESCAPE (IMAGE_MCAL_PSF,       OPIHI_FLT);
     851  if (!strcasecmp (fieldName, "McalAPER"    )) ESCAPE (IMAGE_MCAL_APER,      OPIHI_FLT);
     852  if (!strcasecmp (fieldName, "McalAPERTURE")) ESCAPE (IMAGE_MCAL_APER,      OPIHI_FLT);
     853  if (!strcasecmp (fieldName, "dMcal"       )) ESCAPE (IMAGE_dMCAL,          OPIHI_FLT);
     854  if (!strcasecmp (fieldName, "Xm"          )) ESCAPE (IMAGE_XM,             OPIHI_FLT);
     855  if (!strcasecmp (fieldName, "photcode"    )) ESCAPE (IMAGE_PHOTCODE,       OPIHI_INT);
     856  if (!strcasecmp (fieldName, "exptime"     )) ESCAPE (IMAGE_EXPTIME,        OPIHI_FLT);
     857  if (!strcasecmp (fieldName, "expname"     )) ESCAPE (IMAGE_EXPNAME_AS_INT, OPIHI_INT);
     858  if (!strcasecmp (fieldName, "sidtime"     )) ESCAPE (IMAGE_SIDTIME,        OPIHI_FLT);
    851859
    852860  if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  OPIHI_FLT);
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r40063 r40291  
    5757  if (!strcasecmp (catformat, "PS1_V4"))          return (DVO_FORMAT_PS1_V4);
    5858  if (!strcasecmp (catformat, "PS1_V5"))          return (DVO_FORMAT_PS1_V5);
     59  if (!strcasecmp (catformat, "PS1_V6"))          return (DVO_FORMAT_PS1_V6);
    5960  if (!strcasecmp (catformat, "PS1_V5_LOAD"))     return (DVO_FORMAT_PS1_V5_LOAD);
    6061  if (!strcasecmp (catformat, "PS1_REF"))         return (DVO_FORMAT_PS1_REF);
     
    234235
    235236  if (mode & SECFILT_RESET_CHIP) {
    236     secfilt->M           = NAN;
    237     secfilt->dM          = NAN;
    238     secfilt->Map         = NAN;
    239     secfilt->dMap        = NAN;
    240     secfilt->sMap        = NAN;
    241     secfilt->Mkron       = NAN;
    242     secfilt->dMkron      = NAN;
    243     secfilt->sMkron      = NAN;
     237    secfilt->MpsfChp     = NAN;
     238    secfilt->dMpsfChp    = NAN;
     239    secfilt->sMpsfChp    = NAN;
     240    secfilt->MapChp      = NAN;
     241    secfilt->dMapChp     = NAN;
     242    secfilt->sMapChp     = NAN;
     243    secfilt->MkronChp    = NAN;
     244    secfilt->dMkronChp   = NAN;
     245    secfilt->sMkronChp   = NAN;
    244246
    245247    secfilt->psfQfMax     = NAN;
    246248    secfilt->psfQfPerfMax = NAN;
    247249
    248     secfilt->Mstdev      = NAN;
    249250    secfilt->Mmin        = NAN;
    250251    secfilt->Mmax        = NAN;
     
    316317 measure->Mkron     = NAN;
    317318 measure->dMkron    = NAN;
    318  measure->Mcal      = NAN;
     319 measure->McalPSF   = NAN;
     320 measure->McalAPER  = NAN;
    319321 measure->dMcal     = NAN;
    320322 measure->dt        = NAN;
     
    343345
    344346 measure->Mflat     = 0.0;
    345  measure->dummy2    = 0;
    346347
    347348 measure->Sky       = NAN;
     
    394395 measure->D         = NAN;
    395396 measure->M         = NAN;
    396  measure->Mcal      = NAN;
     397 measure->McalPSF   = NAN;
     398 measure->McalAPER  = NAN;
    397399 measure->dM        = NAN;
    398400
     
    922924    for (in = out = i = 0; i < catalog[0].Naverage; i++) {
    923925      for (j = 0; j < catalog[0].Nsecfilt; j++, in++, out++) {
    924         outsec[out].M      = insec[in].M;
    925         outsec[out].dM     = insec[in].dM;
    926         outsec[out].Mchisq = insec[in].Mchisq;
     926        outsec[out].MpsfChp  = insec[in].MpsfChp;
     927        outsec[out].dMpsfChp = insec[in].dMpsfChp;
     928        outsec[out].Mchisq   = insec[in].Mchisq;
    927929      }
    928930      for (j = 0; j < Nextra; j++, out++) {
    929         outsec[out].M      = NAN;
    930         outsec[out].dM    = NAN;
    931         outsec[out].Mchisq = NAN;
     931        outsec[out].MpsfChp  = NAN;
     932        outsec[out].dMpsfChp = NAN;
     933        outsec[out].Mchisq   = NAN;
    932934      }
    933935    }
  • trunk/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r40063 r40291  
    9191      FORMAT_CASE (PS1_V4,      PS1_V4);
    9292      FORMAT_CASE (PS1_V5,      PS1_V5);
     93      FORMAT_CASE (PS1_V6,      PS1_V6);
    9394      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    9495      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    288289  if (catalog[0].catformat == DVO_FORMAT_PS1_V4)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V4");
    289290  if (catalog[0].catformat == DVO_FORMAT_PS1_V5)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5");
     291  if (catalog[0].catformat == DVO_FORMAT_PS1_V6)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V6");
    290292  if (catalog[0].catformat == DVO_FORMAT_PS1_V5_LOAD)     gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V5_LOAD");
    291293  if (catalog[0].catformat == DVO_FORMAT_PS1_REF)         gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_REF");
     
    394396      FORMAT_CASE (PS1_V4,      PS1_V4);
    395397      FORMAT_CASE (PS1_V5,      PS1_V5);
     398      FORMAT_CASE (PS1_V6,      PS1_V6);
    396399      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    397400      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    448451      FORMAT_CASE (PS1_V4,      PS1_V4);
    449452      FORMAT_CASE (PS1_V5,      PS1_V5);
     453      FORMAT_CASE (PS1_V6,      PS1_V6);
    450454      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    451455      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    505509      FORMAT_CASE (PS1_V3,      PS1_V3);
    506510      FORMAT_CASE (PS1_V5,      PS1_V5);
     511      FORMAT_CASE (PS1_V6,      PS1_V6);
    507512      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    508513      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    559564      FORMAT_CASE (PS1_V4,      PS1_V4);
    560565      FORMAT_CASE (PS1_V5,      PS1_V5);
     566      FORMAT_CASE (PS1_V6,      PS1_V6);
    561567      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    562568      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    617623      FORMAT_CASE (PS1_V4,      PS1_V4);
    618624      FORMAT_CASE (PS1_V5,      PS1_V5);
     625      FORMAT_CASE (PS1_V6,      PS1_V6);
    619626      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    620627      FORMAT_CASE (PS1_REF,     PS1_REF);
     
    671678      FORMAT_CASE (PS1_V4,      PS1_V4);
    672679      FORMAT_CASE (PS1_V5,      PS1_V5);
     680      FORMAT_CASE (PS1_V6,      PS1_V6);
    673681      FORMAT_CASE (PS1_V5_LOAD, PS1_V5_LOAD);
    674682      FORMAT_CASE (PS1_REF,     PS1_REF);
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r39395 r40291  
    464464  catalog[0].Nmissing_disk = Nmissing;
    465465  catalog[0].Nsecfilt_disk = Naverage * Nsecfilt;
    466   catalog[0].Nlensing_disk  = Nlensing;
    467   catalog[0].Nlensobj_disk  = Nlensobj;
    468   catalog[0].Nstarpar_disk  = Nstarpar;
     466  catalog[0].Nlensing_disk = Nlensing;
     467  catalog[0].Nlensobj_disk = Nlensobj;
     468  catalog[0].Nstarpar_disk = Nstarpar;
    469469  catalog[0].Ngalphot_disk = Ngalphot;
    470470
  • trunk/Ohana/src/libdvo/src/dvo_convert.c

    r40063 r40291  
    4242  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V4",          PS1_V4);
    4343  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5);
     44  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V6",          PS1_V6);
    4445  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5_LOAD",     PS1_V5_LOAD);
    4546  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF);
     
    133134  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V4",          PS1_V4,          PS1_V4);
    134135  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5",          PS1_V5,          PS1_V5);
     136  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V6",          PS1_V6,          PS1_V6);
    135137  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    136138  CONVERT_FORMAT ("DVO_AVERAGE_PS1_REF",         PS1_REF,         PS1_REF);
     
    171173      FORMAT_CASE (PS1_V4,          PS1_V4);
    172174      FORMAT_CASE (PS1_V5,          PS1_V5);
     175      FORMAT_CASE (PS1_V6,          PS1_V6);
    173176      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    174177      FORMAT_CASE (PS1_REF,         PS1_REF);
     
    270273  CONVERT_FORMAT ("DVO_MEASURE_PS1_V4",          PS1_V4,          PS1_V4,          FALSE);
    271274  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5",          PS1_V5,          PS1_V5,          TRUE);
     275  CONVERT_FORMAT ("DVO_MEASURE_PS1_V6",          PS1_V6,          PS1_V6,          TRUE);
    272276  CONVERT_FORMAT ("DVO_MEASURE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD,     TRUE);
    273277  CONVERT_FORMAT ("DVO_MEASURE_PS1_REF",         PS1_REF,         PS1_REF,         FALSE);
     
    310314      FORMAT_CASE (PS1_V4,          PS1_V4,          FALSE);
    311315      FORMAT_CASE (PS1_V5,          PS1_V5,          TRUE);
     316      FORMAT_CASE (PS1_V6,          PS1_V6,          TRUE);
    312317      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD,     TRUE);
    313318      FORMAT_CASE (PS1_REF,         PS1_REF,         FALSE);
     
    391396  SKIPPING_FORMAT ("DVO_MISSING_PS1_V4",          PS1_V4,          PS1_V4);
    392397  SKIPPING_FORMAT ("DVO_MISSING_PS1_V5",          PS1_V5,          PS1_V5);
     398  SKIPPING_FORMAT ("DVO_MISSING_PS1_V6",          PS1_V6,          PS1_V6);
    393399  SKIPPING_FORMAT ("DVO_MISSING_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    394400# undef CONVERT_FORMAT
     
    466472  CONVERT_FORMAT ("DVO_SECFILT_PS1_V4",          PS1_V4,          PS1_V4);
    467473  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5",          PS1_V5,          PS1_V5);
     474  CONVERT_FORMAT ("DVO_SECFILT_PS1_V6",          PS1_V6,          PS1_V6);
    468475  CONVERT_FORMAT ("DVO_SECFILT_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    469476  CONVERT_FORMAT ("DVO_SECFILT_PS1_REF",         PS1_REF,         PS1_REF);
     
    504511      FORMAT_CASE (PS1_V4,          PS1_V4);
    505512      FORMAT_CASE (PS1_V5,          PS1_V5);
     513      FORMAT_CASE (PS1_V6,          PS1_V6);
    506514      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    507515      FORMAT_CASE (PS1_REF,         PS1_REF);
     
    612620  SKIPPING_FORMAT ("DVO_LENSING_PS1_V4",          PS1_V4,          PS1_V4);
    613621  CONVERT_FORMAT  ("DVO_LENSING_PS1_V5",          PS1_V5,          PS1_V5_R3);
     622  CONVERT_FORMAT  ("DVO_LENSING_PS1_V6",          PS1_V6,          PS1_V6);
    614623  CONVERT_FORMAT  ("DVO_LENSING_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    615624  SKIPPING_FORMAT ("DVO_LENSING_PS1_SIM",         PS1_SIM,         PS1_SIM);
     
    652661//    FORMAT_CASE (PS1_V4,          PS1_V4);
    653662      FORMAT_CASE (PS1_V5,          PS1_V5_R3);
     663      FORMAT_CASE (PS1_V6,          PS1_V6);
    654664      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    655665# undef FORMAT_CASE
     
    732742  SKIPPING_FORMAT ("DVO_LENSOBJ_PS1_V4",          PS1_V4,          PS1_V4);
    733743  CONVERT_FORMAT  ("DVO_LENSOBJ_PS1_V5",          PS1_V5,          PS1_V5_R1);
     744  CONVERT_FORMAT  ("DVO_LENSOBJ_PS1_V6",          PS1_V6,          PS1_V6);
    734745  CONVERT_FORMAT  ("DVO_LENSOBJ_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    735746  SKIPPING_FORMAT ("DVO_LENSOBJ_PS1_SIM",         PS1_SIM,         PS1_SIM);
     
    772783//    FORMAT_CASE (PS1_V4,          PS1_V4);
    773784      FORMAT_CASE (PS1_V5,          PS1_V5_R1);
     785      FORMAT_CASE (PS1_V6,          PS1_V6);
    774786      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    775787# undef FORMAT_CASE
     
    840852  SKIPPING_FORMAT ("DVO_STARPAR_PS1_V4",          PS1_V4,          PS1_V4);
    841853  CONVERT_FORMAT  ("DVO_STARPAR_PS1_V5",          PS1_V5,          PS1_V5);
     854  CONVERT_FORMAT  ("DVO_STARPAR_PS1_V6",          PS1_V6,          PS1_V6);
    842855  CONVERT_FORMAT  ("DVO_STARPAR_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    843856# undef CONVERT_FORMAT
     
    880893//    FORMAT_CASE (PS1_V4,          PS1_V4);
    881894      FORMAT_CASE (PS1_V5,          PS1_V5);
     895      FORMAT_CASE (PS1_V6,          PS1_V6);
    882896      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    883897# undef FORMAT_CASE
     
    961975  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_V4",          PS1_V4,          PS1_V4);
    962976  CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V5",          PS1_V5,          PS1_V5_R1);
     977  CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V6",          PS1_V6,          PS1_V6);
    963978  CONVERT_FORMAT  ("DVO_GALPHOT_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    964979  SKIPPING_FORMAT ("DVO_GALPHOT_PS1_SIM",         PS1_SIM,         PS1_SIM);
     
    10011016//    FORMAT_CASE (PS1_V4,          PS1_V4);
    10021017      FORMAT_CASE (PS1_V5,          PS1_V5_R1);
     1018      FORMAT_CASE (PS1_V6,          PS1_V6);
    10031019      FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    10041020# undef FORMAT_CASE
     
    10751091  CONVERT_FORMAT ("DVO_IMAGE_PS1_V4",          PS1_V4,          PS1_V4);
    10761092  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5",          PS1_V5,          PS1_V5);
     1093  CONVERT_FORMAT ("DVO_IMAGE_PS1_V6",          PS1_V6,          PS1_V6);
    10771094  CONVERT_FORMAT ("DVO_IMAGE_PS1_V5_LOAD",     PS1_V5_LOAD,     PS1_V5_LOAD);
    10781095  CONVERT_FORMAT ("DVO_IMAGE_PS1_REF",         PS1_REF,         PS1_REF);
     
    10961113    tmpImage = ImageInternalTo_##TYPE ((Image *) ftable[0].buffer, Nimage); \
    10971114    free (ftable[0].buffer);                                            \
     1115    ftable[0].buffer = NULL;                                            \
    10981116    gfits_free_header (ftable->header);                                 \
    10991117    gfits_table_set_Image_##TYPE (ftable, tmpImage, Nimage, TRUE);      \
     
    11141132    FORMAT_CASE (PS1_V4,          PS1_V4);
    11151133    FORMAT_CASE (PS1_V5,          PS1_V5);
     1134    FORMAT_CASE (PS1_V6,          PS1_V6);
    11161135    FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    11171136    FORMAT_CASE (PS1_REF,         PS1_REF);
     
    11661185    FORMAT_CASE (PS1_V4,          PS1_V4);
    11671186    FORMAT_CASE (PS1_V5,          PS1_V5);
     1187    FORMAT_CASE (PS1_V6,          PS1_V6);
    11681188    FORMAT_CASE (PS1_V5_LOAD,     PS1_V5_LOAD);
    11691189    FORMAT_CASE (PS1_REF,         PS1_REF);
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].dM         = in[i].dM;
    2122    out[i].dt         = in[i].dt;
     
    6465    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6566    out[i].M          = in[i].M;
    66     out[i].Mcal       = in[i].Mcal;
     67    out[i].Mcal       = in[i].McalPSF;
    6768    out[i].dM         = in[i].dM;
    6869    out[i].dt         = in[i].dt;
     
    182183    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    183184
    184     out[i].M     = in[i].M;     
    185     out[i].dM    = in[i].dM;     
     185    out[i].MpsfChp     = in[i].M;     
     186    out[i].dMpsfChp    = in[i].dM;     
     187
    186188    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    187189    out[i].Ncode = in[i].Ncode;
     
    199201
    200202  for (i = 0; i < Nvalues; i++) {
    201     out[i].M     = in[i].M;     
    202     out[i].dM    = in[i].dM;     
     203    out[i].M             = in[i].MpsfChp;     
     204    out[i].dM            = in[i].dMpsfChp;     
     205
    203206    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    204207    out[i].Ncode = in[i].Ncode;
     
    237240    out[i].apmifit          = in[i].apmifit;
    238241    out[i].dapmifit         = in[i].dapmifit;
    239     out[i].Mcal             = in[i].Mcal;
     242
     243    out[i].McalPSF          = in[i].Mcal;
     244    out[i].McalAPER         = in[i].Mcal;
    240245    out[i].dMcal            = in[i].dMcal;
    241     out[i].Xm               = in[i].Xm;
     246    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     247
    242248    out[i].photcode         = in[i].photcode;
    243249    out[i].exptime          = in[i].exptime;
     
    306312    out[i].apmifit          = in[i].apmifit;
    307313    out[i].dapmifit         = in[i].dapmifit;
    308     out[i].Mcal             = in[i].Mcal;
     314
     315    out[i].Mcal             = in[i].McalPSF;
    309316    out[i].dMcal            = in[i].dMcal;
    310     out[i].Xm               = in[i].Xm;
     317    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     318
    311319    out[i].photcode         = in[i].photcode;
    312320    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].Map        = in[i].Map;
    2122    out[i].dM         = in[i].dM;
     
    6263    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    6364    out[i].M          = in[i].M;
    64     out[i].Mcal       = in[i].Mcal;
     65    out[i].Mcal       = in[i].McalPSF;
    6566    out[i].Map        = in[i].Map;
    6667    out[i].dM         = in[i].dM;
     
    177178    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    178179
    179     out[i].M     = in[i].M;     
    180     out[i].dM    = in[i].dM;     
     180    out[i].MpsfChp     = in[i].M;     
     181    out[i].dMpsfChp    = in[i].dM;     
     182
    181183    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    182184    out[i].Ncode = in[i].Ncode;
     
    194196
    195197  for (i = 0; i < Nvalues; i++) {
    196     out[i].M     = in[i].M;     
    197     out[i].dM    = in[i].dM;     
     198    out[i].M             = in[i].MpsfChp;     
     199    out[i].dM            = in[i].dMpsfChp;     
     200
    198201    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    199202    out[i].Ncode = in[i].Ncode;
     
    232235    out[i].apmifit          = in[i].apmifit;
    233236    out[i].dapmifit         = in[i].dapmifit;
    234     out[i].Mcal             = in[i].Mcal;
     237
     238    out[i].McalPSF          = in[i].Mcal;
     239    out[i].McalAPER         = in[i].Mcal;
    235240    out[i].dMcal            = in[i].dMcal;
    236     out[i].Xm               = in[i].Xm;
     241    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     242
    237243    out[i].photcode         = in[i].photcode;
    238244    out[i].exptime          = in[i].exptime;
     
    298304    out[i].apmifit          = in[i].apmifit;
    299305    out[i].dapmifit         = in[i].dapmifit;
    300     out[i].Mcal             = in[i].Mcal;
     306
     307    out[i].Mcal             = in[i].McalPSF;
    301308    out[i].dMcal            = in[i].dMcal;
    302     out[i].Xm               = in[i].Xm;
     309    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     310
    303311    out[i].photcode         = in[i].photcode;
    304312    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r37807 r40291  
    3434    out[i].apmifit          = in[i].apmifit;
    3535    out[i].dapmifit         = in[i].dapmifit;
    36     out[i].Mcal             = in[i].Mcal;
     36
     37    out[i].McalPSF          = in[i].Mcal;
     38    out[i].McalAPER         = in[i].Mcal;
    3739    out[i].dMcal            = in[i].dMcal;
    38     out[i].Xm               = in[i].Xm;
     40    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     41
    3942    out[i].photcode         = in[i].photcode;
    4043    out[i].exptime          = in[i].exptime;
     
    9598    out[i].apmifit          = in[i].apmifit;
    9699    out[i].dapmifit         = in[i].dapmifit;
    97     out[i].Mcal             = in[i].Mcal;
     100
     101    out[i].Mcal             = in[i].McalPSF;
    98102    out[i].dMcal            = in[i].dMcal;
    99     out[i].Xm               = in[i].Xm;
     103    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     104
    100105    out[i].photcode         = in[i].photcode;
    101106    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r39457 r40291  
    114114    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    115115
    116     out[i].M     = in[i].M;     
    117     out[i].dM    = in[i].dM;     
     116    out[i].MpsfChp     = in[i].M;     
     117    out[i].dMpsfChp    = in[i].dM;     
    118118 }
    119119  return (out);
     
    128128
    129129  for (i = 0; i < Nvalues; i++) {
    130     out[i].M     = in[i].M;     
    131     out[i].dM    = in[i].dM;     
     130    out[i].M             = in[i].MpsfChp;     
     131    out[i].dM            = in[i].dMpsfChp;     
    132132  }
    133133  return (out);
     
    163163    out[i].apmifit          = in[i].apmifit;
    164164    out[i].dapmifit         = in[i].dapmifit;
    165     out[i].Mcal             = in[i].Mcal;
     165
     166    out[i].McalPSF          = in[i].Mcal;
     167    out[i].McalAPER         = in[i].Mcal;
    166168    out[i].dMcal            = in[i].dMcal;
    167     out[i].Xm               = in[i].Xm;
     169    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     170
    168171    out[i].photcode         = in[i].photcode;
    169172    out[i].exptime          = in[i].exptime;
     
    227230    out[i].apmifit          = in[i].apmifit;
    228231    out[i].dapmifit         = in[i].dapmifit;
    229     out[i].Mcal             = in[i].Mcal;
     232
     233    out[i].Mcal             = in[i].McalPSF;
    230234    out[i].dMcal            = in[i].dMcal;
    231     out[i].Xm               = in[i].Xm;
     235    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     236
    232237    out[i].photcode         = in[i].photcode;
    233238    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_SIM.c

    r39457 r40291  
    1818    out[i].M          = in[i].M;
    1919    out[i].dM         = in[i].dM;
    20     out[i].Mcal       = in[i].Mcal;
     20    out[i].McalPSF    = in[i].Mcal;
     21    out[i].McalAPER   = in[i].Mcal;
    2122    out[i].dt         = in[i].dt;
    2223    out[i].airmass    = in[i].airmass;
     
    6465    out[i].M          = in[i].M;
    6566    out[i].dM         = in[i].dM;
    66     out[i].Mcal       = in[i].Mcal;
     67    out[i].Mcal       = in[i].McalPSF;
    6768    out[i].dt         = in[i].dt;
    6869    out[i].airmass    = in[i].airmass;
     
    199200    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    200201
    201     out[i].M             = in[i].M;     
    202     out[i].dM            = in[i].dM;     
     202    out[i].MpsfChp     = in[i].M;     
     203    out[i].dMpsfChp    = in[i].dM;     
     204
    203205    out[i].Ncode         = in[i].Ncode;
    204206    out[i].Nused         = in[i].Nused;
     
    217219  for (i = 0; i < Nvalues; i++) {
    218220
    219     out[i].M             = in[i].M;     
    220     out[i].dM            = in[i].dM;     
     221    out[i].M             = in[i].MpsfChp;     
     222    out[i].dM            = in[i].dMpsfChp;     
     223
    221224    out[i].Ncode         = in[i].Ncode;
    222225    out[i].Nused         = in[i].Nused;
     
    320323    out[i].apmifit          = in[i].apmifit;
    321324    out[i].dapmifit         = in[i].dapmifit;
    322     out[i].Mcal             = in[i].Mcal;
     325
     326    out[i].McalPSF          = in[i].Mcal;
     327    out[i].McalAPER         = in[i].Mcal;
    323328    out[i].dMcal            = in[i].dMcal;
    324     out[i].Xm               = in[i].Xm;
     329    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     330
    325331    out[i].photcode         = in[i].photcode;
    326332    out[i].exptime          = in[i].exptime;
     
    386392    out[i].apmifit          = in[i].apmifit;
    387393    out[i].dapmifit         = in[i].dapmifit;
    388     out[i].Mcal             = in[i].Mcal;
     394
     395    out[i].Mcal             = in[i].McalPSF;
    389396    out[i].dMcal            = in[i].dMcal;
    390     out[i].Xm               = in[i].Xm;
     397    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     398
    391399    out[i].photcode         = in[i].photcode;
    392400    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].Map        = in[i].Map;
    2122    out[i].dM         = in[i].dM;
     
    7172    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7273    out[i].M          = in[i].M;
    73     out[i].Mcal       = in[i].Mcal;
     74    out[i].Mcal       = in[i].McalPSF;
    7475    out[i].Map        = in[i].Map;
    7576    out[i].dM         = in[i].dM;
     
    197198    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    198199
    199     out[i].M     = in[i].M;     
    200     out[i].dM    = in[i].dM;     
     200    out[i].MpsfChp     = in[i].M;     
     201    out[i].dMpsfChp    = in[i].dM;     
     202
    201203    out[i].Mchisq= in[i].Mchisq;     
    202204    out[i].Ncode = in[i].Ncode;
     
    216218
    217219  for (i = 0; i < Nvalues; i++) {
    218     out[i].M     = in[i].M;     
    219     out[i].dM    = in[i].dM;     
     220    out[i].M             = in[i].MpsfChp;     
     221    out[i].dM            = in[i].dMpsfChp;     
     222
    220223    out[i].Mchisq= in[i].Mchisq;     
    221224    out[i].Ncode = in[i].Ncode;
     
    256259    out[i].apmifit          = in[i].apmifit;
    257260    out[i].dapmifit         = in[i].dapmifit;
    258     out[i].Mcal             = in[i].Mcal;
     261
     262    out[i].McalPSF          = in[i].Mcal;
     263    out[i].McalAPER         = in[i].Mcal;
    259264    out[i].dMcal            = in[i].dMcal;
    260     out[i].Xm               = in[i].Xm;
     265    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     266
    261267    out[i].photcode         = in[i].photcode;
    262268    out[i].exptime          = in[i].exptime;
     
    321327    out[i].apmifit          = in[i].apmifit;
    322328    out[i].dapmifit         = in[i].dapmifit;
    323     out[i].Mcal             = in[i].Mcal;
     329
     330    out[i].Mcal             = in[i].McalPSF;
    324331    out[i].dMcal            = in[i].dMcal;
    325     out[i].Xm               = in[i].Xm;
     332    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     333
    326334    out[i].photcode         = in[i].photcode;
    327335    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].Map        = in[i].Map;
    2122    out[i].dM         = in[i].dM;
     
    7273    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7374    out[i].M          = in[i].M;
    74     out[i].Mcal       = in[i].Mcal;
     75    out[i].Mcal       = in[i].McalPSF;
    7576    out[i].Map        = in[i].Map;
    7677    out[i].dM         = in[i].dM;
     
    206207    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    207208
    208     out[i].M     = in[i].M;     
    209     out[i].dM    = in[i].dM;     
     209    out[i].MpsfChp     = in[i].M;     
     210    out[i].dMpsfChp    = in[i].dM;     
     211
    210212    out[i].Mchisq= in[i].Mchisq;     
    211213    out[i].flags = in[i].flags;     
     
    226228
    227229  for (i = 0; i < Nvalues; i++) {
    228     out[i].M     = in[i].M;     
    229     out[i].dM    = in[i].dM;     
     230    out[i].M             = in[i].MpsfChp;     
     231    out[i].dM            = in[i].dMpsfChp;     
     232
    230233    out[i].Mchisq= in[i].Mchisq;     
    231234    out[i].flags = in[i].flags;     
     
    267270    out[i].apmifit          = in[i].apmifit;
    268271    out[i].dapmifit         = in[i].dapmifit;
    269     out[i].Mcal             = in[i].Mcal;
     272
     273    out[i].McalPSF          = in[i].Mcal;
     274    out[i].McalAPER         = in[i].Mcal;
    270275    out[i].dMcal            = in[i].dMcal;
    271     out[i].Xm               = in[i].Xm;
     276    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     277
    272278    out[i].photcode         = in[i].photcode;
    273279    out[i].exptime          = in[i].exptime;
     
    332338    out[i].apmifit          = in[i].apmifit;
    333339    out[i].dapmifit         = in[i].dapmifit;
    334     out[i].Mcal             = in[i].Mcal;
     340
     341    out[i].Mcal             = in[i].McalPSF;
    335342    out[i].dMcal            = in[i].dMcal;
    336     out[i].Xm               = in[i].Xm;
     343    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     344
    337345    out[i].photcode         = in[i].photcode;
    338346    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].Map        = in[i].Map;
    2122    out[i].dM         = in[i].dM;
     
    7273    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    7374    out[i].M          = in[i].M;
    74     out[i].Mcal       = in[i].Mcal;
     75    out[i].Mcal       = in[i].McalPSF;
    7576    out[i].Map        = in[i].Map;
    7677    out[i].dM         = in[i].dM;
     
    210211    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    211212
    212     out[i].M           = in[i].M;     
    213     out[i].Map         = in[i].Map;     
    214     out[i].dM          = in[i].dM;     
     213    out[i].MpsfChp     = in[i].M;     
     214    out[i].sMpsfChp    = in[i].Mstdev;     
     215    out[i].dMpsfChp    = in[i].dM;     
     216    out[i].MapChp      = in[i].Map;     
     217
    215218    out[i].Mchisq      = in[i].Mchisq;     
    216219    out[i].flags       = in[i].flags;     
     
    219222    out[i].Mmin        = in[i].M_20*0.001;     
    220223    out[i].Mmax        = in[i].M_80*0.001;     
    221     out[i].Mstdev      = in[i].Mstdev;     
    222224    out[i].ubercalDist = in[i].ubercalDist;     
    223225 }
     
    233235
    234236  for (i = 0; i < Nvalues; i++) {
    235     out[i].M           = in[i].M;     
    236     out[i].Map         = in[i].Map;     
    237     out[i].dM          = in[i].dM;     
     237    out[i].M             = in[i].MpsfChp;     
     238    out[i].dM            = in[i].dMpsfChp;     
     239    out[i].Mstdev        = in[i].sMpsfChp;     
     240    out[i].Map           = in[i].MapChp;     
     241
    238242    out[i].Mchisq      = in[i].Mchisq;     
    239243    out[i].flags       = in[i].flags;     
     
    242246    out[i].M_20        = in[i].Mmin*1000.0;     
    243247    out[i].M_80        = in[i].Mmax*1000.0;     
    244     out[i].Mstdev      = in[i].Mstdev;     
    245248    out[i].ubercalDist = in[i].ubercalDist;     
    246249  }
     
    277280    out[i].apmifit          = in[i].apmifit;
    278281    out[i].dapmifit         = in[i].dapmifit;
    279     out[i].Mcal             = in[i].Mcal;
     282
     283    out[i].McalPSF          = in[i].Mcal;
     284    out[i].McalAPER         = in[i].Mcal;
    280285    out[i].dMcal            = in[i].dMcal;
    281     out[i].Xm               = in[i].Xm;
     286    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     287
    282288    out[i].photcode         = in[i].photcode;
    283289    out[i].exptime          = in[i].exptime;
     
    342348    out[i].apmifit          = in[i].apmifit;
    343349    out[i].dapmifit         = in[i].dapmifit;
    344     out[i].Mcal             = in[i].Mcal;
     350
     351    out[i].Mcal             = in[i].McalPSF;
    345352    out[i].dMcal            = in[i].dMcal;
    346     out[i].Xm               = in[i].Xm;
     353    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     354
    347355    out[i].photcode         = in[i].photcode;
    348356    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r39457 r40291  
    1717    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    1818    out[i].M          = in[i].M;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021    out[i].Map        = in[i].Map;
    2122    out[i].Mkron      = in[i].Mkron;
     
    8182    out[i].dD         = 3600.0*(ave[averef].D - in[i].D);
    8283    out[i].M          = in[i].M;
    83     out[i].Mcal       = in[i].Mcal;
     84    out[i].Mcal       = in[i].McalPSF;
    8485    out[i].Map        = in[i].Map;
    8586    out[i].Mkron      = in[i].Mkron;
     
    234235    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    235236
    236     out[i].M             = in[i].M;     
    237     out[i].Map           = in[i].Map;     
    238     out[i].Mkron         = in[i].Mkron;     
    239     out[i].dMkron        = in[i].dMkron;     
    240     out[i].dM            = in[i].dM;     
     237    out[i].MpsfChp       = in[i].M;     
     238    out[i].sMpsfChp      = in[i].Mstdev;     
     239    out[i].dMpsfChp      = in[i].dM;     
     240    out[i].MapChp        = in[i].Map;     
     241    out[i].MkronChp      = in[i].Mkron;     
     242
    241243    out[i].Mchisq        = in[i].Mchisq;     
    242244    out[i].FpsfStk       = in[i].FluxPSF;
     
    249251    out[i].Mmin          = in[i].M_20*0.001;     
    250252    out[i].Mmax          = in[i].M_80*0.001;     
    251     out[i].Mstdev        = in[i].Mstdev;     
    252253    out[i].ubercalDist   = in[i].ubercalDist;     
    253254    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     
    265266
    266267  for (i = 0; i < Nvalues; i++) {
    267     out[i].M             = in[i].M;     
    268     out[i].Map           = in[i].Map;     
    269     out[i].Mkron         = in[i].Mkron;     
    270     out[i].dMkron        = in[i].dMkron;     
    271     out[i].dM            = in[i].dM;     
     268    out[i].M             = in[i].MpsfChp;     
     269    out[i].dM            = in[i].dMpsfChp;     
     270    out[i].Mstdev        = in[i].sMpsfChp;     
     271    out[i].Map           = in[i].MapChp;     
     272    out[i].Mkron         = in[i].MkronChp;     
     273
    272274    out[i].Mchisq        = in[i].Mchisq;
    273275    out[i].FluxPSF       = in[i].FpsfStk;
     
    280282    out[i].M_20          = in[i].Mmin*1000.0;     
    281283    out[i].M_80          = in[i].Mmax*1000.0;     
    282     out[i].Mstdev        = in[i].Mstdev;     
    283284    out[i].ubercalDist   = in[i].ubercalDist;     
    284285    out[i].stackPrmryOff = in[i].stackPrmryOff;     
     
    317318    out[i].apmifit          = in[i].apmifit;
    318319    out[i].dapmifit         = in[i].dapmifit;
    319     out[i].Mcal             = in[i].Mcal;
     320
     321    out[i].McalPSF          = in[i].Mcal;
     322    out[i].McalAPER         = in[i].Mcal;
    320323    out[i].dMcal            = in[i].dMcal;
    321     out[i].Xm               = in[i].Xm;
     324    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     325
    322326    out[i].photcode         = in[i].photcode;
    323327    out[i].exptime          = in[i].exptime;
     
    382386    out[i].apmifit          = in[i].apmifit;
    383387    out[i].dapmifit         = in[i].dapmifit;
    384     out[i].Mcal             = in[i].Mcal;
     388
     389    out[i].Mcal             = in[i].McalPSF;
    385390    out[i].dMcal            = in[i].dMcal;
    386     out[i].Xm               = in[i].Xm;
     391    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     392
    387393    out[i].photcode         = in[i].photcode;
    388394    out[i].exptime          = in[i].exptime;
     
    513519    out[i].D          = ave[averef].D - in[i].dD / 3600.0;
    514520    out[i].M          = in[i].M;
    515     out[i].Mcal       = in[i].Mcal;
     521    out[i].McalPSF    = in[i].Mcal;
     522    out[i].McalAPER   = in[i].Mcal;
    516523    out[i].Map        = in[i].Map;
    517524    out[i].Mkron      = in[i].Mkron;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r39486 r40291  
    2222    out[i].Mkron      = in[i].Mkron;
    2323    out[i].dMkron     = in[i].dMkron;
    24     out[i].Mcal       = in[i].Mcal;
     24    out[i].McalPSF    = in[i].Mcal;
     25    out[i].McalAPER   = in[i].Mcal;
    2526    out[i].dMcal      = in[i].dMcal;
    2627    out[i].dt         = in[i].dt;
     
    9697    out[i].Mkron      = in[i].Mkron;
    9798    out[i].dMkron     = in[i].dMkron;
    98     out[i].Mcal       = in[i].Mcal;
     99    out[i].Mcal       = in[i].McalPSF;
    99100    out[i].dMcal      = in[i].dMcal;
    100101    out[i].dt         = in[i].dt;
     
    311312    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    312313
    313     out[i].M             = in[i].M;     
    314     out[i].dM            = in[i].dM;     
    315     out[i].Map           = in[i].Map;     
    316     out[i].dMap          = in[i].dMap;     
    317     out[i].sMap          = in[i].sMap;     
    318     out[i].Mkron         = in[i].Mkron;     
    319     out[i].dMkron        = in[i].dMkron;     
    320     out[i].sMkron        = in[i].sMkron;     
     314    out[i].MpsfChp       = in[i].M;     
     315    out[i].sMpsfChp      = in[i].Mstdev;     
     316    out[i].dMpsfChp      = in[i].dM;     
     317    out[i].MapChp        = in[i].Map;     
     318    out[i].dMapChp       = in[i].dMap;     
     319    out[i].sMapChp       = in[i].sMap;     
     320    out[i].MkronChp      = in[i].Mkron;     
     321    out[i].dMkronChp     = in[i].dMkron;     
     322    out[i].sMkronChp     = in[i].sMkron;     
    321323
    322324    out[i].psfQfMax      = in[i].psfQfMax;     
    323325    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;     
    324326
    325     out[i].Mstdev        = in[i].Mstdev;     
    326327    out[i].Mmin          = in[i].Mmin;     
    327328    out[i].Mmax          = in[i].Mmax;     
     
    389390  for (i = 0; i < Nvalues; i++) {
    390391
    391     out[i].M             = in[i].M;     
    392     out[i].dM            = in[i].dM;     
    393     out[i].Map           = in[i].Map;     
    394     out[i].dMap          = in[i].dMap;     
    395     out[i].sMap          = in[i].sMap;     
    396     out[i].Mkron         = in[i].Mkron;     
    397     out[i].dMkron        = in[i].dMkron;     
    398     out[i].sMkron        = in[i].sMkron;     
     392    out[i].M             = in[i].MpsfChp;     
     393    out[i].dM            = in[i].dMpsfChp;     
     394    out[i].Mstdev        = in[i].sMpsfChp;     
     395    out[i].Map           = in[i].MapChp;     
     396    out[i].dMap          = in[i].dMapChp;     
     397    out[i].sMap          = in[i].sMapChp;     
     398    out[i].Mkron         = in[i].MkronChp;     
     399    out[i].dMkron        = in[i].dMkronChp;     
     400    out[i].sMkron        = in[i].sMkronChp;     
    399401
    400402    out[i].psfQfMax      = in[i].psfQfMax;     
    401403    out[i].psfQfPerfMax  = in[i].psfQfPerfMax;     
    402404
    403     out[i].Mstdev        = in[i].Mstdev;     
    404405    out[i].Mmin          = in[i].Mmin;     
    405406    out[i].Mmax          = in[i].Mmax;     
     
    11431144    out[i].apmifit          = in[i].apmifit;
    11441145    out[i].dapmifit         = in[i].dapmifit;
    1145     out[i].Mcal             = in[i].Mcal;
     1146
     1147    out[i].McalPSF          = in[i].Mcal;
     1148    out[i].McalAPER         = in[i].Mcal;
    11461149    out[i].dMcal            = in[i].dMcal;
    1147     out[i].Xm               = in[i].Xm;
     1150    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     1151
    11481152    out[i].photcode         = in[i].photcode;
    11491153    out[i].exptime          = in[i].exptime;
     
    12091213    out[i].apmifit          = in[i].apmifit;
    12101214    out[i].dapmifit         = in[i].dapmifit;
    1211     out[i].Mcal             = in[i].Mcal;
     1215
     1216    out[i].Mcal             = in[i].McalPSF;
    12121217    out[i].dMcal            = in[i].dMcal;
    1213     out[i].Xm               = in[i].Xm;
     1218    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     1219
    12141220    out[i].photcode         = in[i].photcode;
    12151221    out[i].exptime          = in[i].exptime;
     
    14951501    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    14961502
    1497     out[i].M             = in[i].M;     
    1498     out[i].dM            = in[i].dM;     
    1499     out[i].Map           = in[i].Map;     
    1500     out[i].dMap          = in[i].dMap;     
    1501     out[i].sMap          = in[i].sMap;     
    1502     out[i].Mkron         = in[i].Mkron;     
    1503     out[i].dMkron        = in[i].dMkron;     
    1504 
    1505     out[i].Mstdev        = in[i].Mstdev;     
     1503    out[i].MpsfChp       = in[i].M;     
     1504    out[i].dMpsfChp      = in[i].dM;     
     1505    out[i].sMpsfChp      = in[i].Mstdev;     
     1506    out[i].MapChp        = in[i].Map;     
     1507    out[i].dMapChp       = in[i].dMap;     
     1508    out[i].sMapChp       = in[i].sMap;     
     1509    out[i].MkronChp      = in[i].Mkron;     
     1510    out[i].dMkronChp     = in[i].dMkron;     
     1511    out[i].sMkronChp     = in[i].sMkron;     
     1512
    15061513    out[i].Mmin          = in[i].Mmin;     
    15071514    out[i].Mmax          = in[i].Mmax;     
     
    16681675    out[i].Mkron      = in[i].Mkron;
    16691676    out[i].dMkron     = in[i].dMkron;
    1670     out[i].Mcal       = in[i].Mcal;
     1677    out[i].McalPSF    = in[i].Mcal;
     1678    out[i].McalAPER   = in[i].Mcal;
    16711679    out[i].dMcal      = in[i].dMcal;
    16721680    out[i].dt         = in[i].dt;
  • trunk/Ohana/src/libdvo/src/dvo_convert_PS1_V5_LOAD.c

    r40063 r40291  
    2222    out[i].Mkron      = in[i].Mkron;
    2323    out[i].dMkron     = in[i].dMkron;
    24     out[i].Mcal       = in[i].Mcal;
     24    out[i].McalPSF    = in[i].Mcal;
     25    out[i].McalAPER   = in[i].Mcal;
    2526    out[i].dMcal      = in[i].dMcal;
    2627    out[i].dt         = in[i].dt;
     
    9697    out[i].Mkron      = in[i].Mkron;
    9798    out[i].dMkron     = in[i].dMkron;
    98     out[i].Mcal       = in[i].Mcal;
     99    out[i].Mcal       = in[i].McalPSF;
    99100    out[i].dMcal      = in[i].dMcal;
    100101    out[i].dt         = in[i].dt;
     
    221222    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    222223
    223     out[i].M             = in[i].M;     
     224    out[i].MpsfChp       = in[i].M;     
    224225    out[i].Ncode         = in[i].Ncode;
    225226    out[i].Nused         = in[i].Nused;
     
    237238  for (i = 0; i < Nvalues; i++) {
    238239
    239     out[i].M             = in[i].M;     
     240    out[i].M             = in[i].MpsfChp;     
    240241    out[i].Ncode         = in[i].Ncode;
    241242    out[i].Nused         = in[i].Nused;
     
    654655    out[i].apmifit          = in[i].apmifit;
    655656    out[i].dapmifit         = in[i].dapmifit;
    656     out[i].Mcal             = in[i].Mcal;
     657
     658    out[i].McalPSF          = in[i].Mcal;
     659    out[i].McalAPER         = in[i].Mcal;
    657660    out[i].dMcal            = in[i].dMcal;
    658     out[i].Xm               = in[i].Xm;
     661    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     662
    659663    out[i].photcode         = in[i].photcode;
    660664    out[i].exptime          = in[i].exptime;
     
    720724    out[i].apmifit          = in[i].apmifit;
    721725    out[i].dapmifit         = in[i].dapmifit;
    722     out[i].Mcal             = in[i].Mcal;
     726
     727    out[i].Mcal             = in[i].McalPSF;
    723728    out[i].dMcal            = in[i].dMcal;
    724     out[i].Xm               = in[i].Xm;
     729    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     730
    725731    out[i].photcode         = in[i].photcode;
    726732    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r38462 r40291  
    2424    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
    2525    out[i].dt       = (in[i].dt      == NAN_S_SHORT) ? NAN : in[i].dt     * 0.001;
    26     out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
     26    out[i].McalPSF  = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
     27    out[i].McalAPER = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
    2728    out[i].Map      = (in[i].Mgal    == NAN_S_SHORT) ? NAN : in[i].Mgal   * 0.001;
    2829    out[i].airmass  = (in[i].airmass == NAN_S_SHORT) ? NAN : in[i].airmass* 0.001;
     
    7273    out[i].dM       = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
    7374    out[i].dt       = isnan(in[i].dt     ) ? NAN_S_SHORT : in[i].dt      * 1000.0;
    74     out[i].Mcal     = isnan(in[i].Mcal   ) ? NAN_S_SHORT : in[i].Mcal    * 1000.0;
     75    out[i].Mcal     = isnan(in[i].McalPSF) ? NAN_S_SHORT : in[i].McalPSF * 1000.0;
    7576    out[i].Mgal     = isnan(in[i].Map    ) ? NAN_S_SHORT : in[i].Map     * 1000.0;
    7677    out[i].airmass  = isnan(in[i].airmass) ? NAN_S_SHORT : in[i].airmass * 1000.0;
     
    109110
    110111    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    111     primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    112     primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;     
     112    primary[0][i].MpsfChp  = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
     113    primary[0][i].dMpsfChp = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;     
    113114    primary[0][i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    114115
     
    142143
    143144    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    144     out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
    145     out[i].dM      = isnan(primary[i].dM) ? NAN_S_SHORT : primary[i].dM  * 1000.0;
     145    out[i].M       = isnan(primary[i].MpsfChp)  ? NAN_S_SHORT : primary[i].MpsfChp   * 1000.0;
     146    out[i].dM      = isnan(primary[i].dMpsfChp) ? NAN_S_SHORT : primary[i].dMpsfChp  * 1000.0;
    146147    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
    147148
     
    172173
    173174    // added or changed for PANSTARRS_DEV_0
    174     out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M   * 0.001;
    175     out[i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM  * 0.001;
     175    out[i].MpsfChp     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M   * 0.001;
     176    out[i].dMpsfChp    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM  * 0.001;
    176177  }
    177178  return (out);
     
    190191
    191192    // added or changed for PANSTARRS_DEV_0
    192     out[i].M     = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M   * 1000.0;
    193     out[i].dM    = isnan(in[i].dM) ? NAN_S_SHORT : in[i].dM  * 1000.0;
     193    out[i].M     = isnan(in[i].MpsfChp)  ? NAN_S_SHORT : in[i].MpsfChp   * 1000.0;
     194    out[i].dM    = isnan(in[i].dMpsfChp) ? NAN_S_SHORT : in[i].dMpsfChp  * 1000.0;
    194195  }
    195196  return (out);
     
    223224    out[i].NX               = in[i].NX;
    224225    out[i].NY               = in[i].NY;
    225     out[i].Xm               = in[i].Xm;
    226226    out[i].photcode         = in[i].source;
    227227    out[i].exptime          = in[i].exptime;
     
    252252    out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
    253253    out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
    254     out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     254
     255    out[i].McalPSF          = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     256    out[i].McalAPER         = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
    255257    out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     258    out[i].McalChiSq        = (in[i].dMcal    == NAN_S_SHORT) ? NAN : pow(10.0, 0.01*in[i].Xm);
     259
    256260    out[i].sidtime          = NAN;
    257261    out[i].latitude         = NAN;
     
    295299    out[i].NY               = in[i].NY;
    296300
    297     out[i].Xm               = in[i].Xm;
    298301    out[i].source           = in[i].photcode;
    299302    out[i].exptime          = in[i].exptime;
     
    324327    out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
    325328    out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
    326     out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
     329
     330    out[i].Mcal             = isnan(in[i].McalPSF ) ? NAN_S_SHORT : in[i].McalPSF  * 1000.0;
    327331    out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
     332    out[i].Xm               = isnan(in[i].dMcal   ) ? NAN_S_SHORT : 100.0*log10(in[i].McalChiSq);
    328333
    329334    // changed or added for PS1_V1
  • trunk/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r38462 r40291  
    2626    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
    2727    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
    28     out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
     28    out[i].McalPSF  = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
     29    out[i].McalAPER = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
    2930    out[i].Map      = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
    3031    out[i].photcode = in[i].source;
     
    5960    out[i].M      = isnan(in[i].M      ) ? NAN_S_SHORT : in[i].M       * 1000.0;
    6061    out[i].dM     = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
    61     out[i].Mcal   = isnan(in[i].Mcal   ) ? NAN_S_SHORT : in[i].Mcal    * 1000.0;
     62    out[i].Mcal   = isnan(in[i].McalPSF) ? NAN_S_SHORT : in[i].McalPSF * 1000.0;
    6263    out[i].source = in[i].photcode;
    6364    out[i].t      = in[i].t;
     
    8990
    9091    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    91     primary[0][i].M    = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    92     primary[0][i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
     92    primary[0][i].MpsfChp = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
     93    primary[0][i].Mchisq  = pow (10.0, 0.01*in[i].Xm);     
    9394
    9495    // added for PANSTARRS_DEV_0
     
    123124
    124125    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    125     out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
     126    out[i].M       = isnan(primary[i].MpsfChp)  ? NAN_S_SHORT : primary[i].MpsfChp   * 1000.0;
    126127    out[i].Xm      = 100.0*log10(primary[i].Mchisq);     
    127128
     
    152153
    153154    // added or changed for PANSTARRS_DEV_0
    154     out[i].M    = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M * 0.001;
     155    out[i].MpsfChp = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M * 0.001;
    155156  }
    156157  return (out);
     
    169170
    170171    // added or changed for PANSTARRS_DEV_0
    171     out[i].M    = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M * 1000.0;
     172    out[i].M    = isnan(in[i].MpsfChp)  ? NAN_S_SHORT : in[i].MpsfChp * 1000.0;
    172173  }
    173174  return (out);
     
    202203    out[i].NY               = in[i].NY;
    203204
    204     out[i].Xm               = in[i].Xm;
    205205    out[i].photcode         = in[i].source;
    206206    out[i].exptime          = in[i].exptime;
     
    231231    out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
    232232    out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
    233     out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     233
     234    out[i].McalPSF          = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     235    out[i].McalAPER         = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
    234236    out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     237    out[i].McalChiSq        = (in[i].dMcal    == NAN_S_SHORT) ? NAN : pow(10.0, 0.01*in[i].Xm);
     238
    235239    out[i].sidtime          = NAN;
    236240    out[i].latitude         = NAN;
     
    274278    out[i].NY               = in[i].NY;
    275279
    276     out[i].Xm               = in[i].Xm;
    277280    out[i].source           = in[i].photcode;
    278281    out[i].exptime          = in[i].exptime;
     
    303306    out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
    304307    out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
    305     out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
     308
     309    out[i].Mcal             = isnan(in[i].McalPSF ) ? NAN_S_SHORT : in[i].McalPSF  * 1000.0;
    306310    out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
     311    out[i].Xm               = isnan(in[i].dMcal   ) ? NAN_S_SHORT : 100.0*log10(in[i].McalChiSq);
    307312
    308313    // changed or added for PS1_V1
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r39457 r40291  
    1717    out[i].M          = in[i].M;
    1818    out[i].dM         = in[i].dM;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021
    2122    out[i].airmass    = in[i].airmass;
     
    6869    out[i].M          = in[i].M;
    6970    out[i].dM         = in[i].dM;
    70     out[i].Mcal       = in[i].Mcal;
     71    out[i].Mcal       = in[i].McalPSF;
    7172    out[i].airmass    = in[i].airmass;
    7273    out[i].az         = in[i].az;
     
    188189    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    189190
    190     out[i].M     = in[i].M;     
    191     out[i].dM    = in[i].dM;     
     191    out[i].MpsfChp     = in[i].M;     
     192    out[i].dMpsfChp    = in[i].dM;     
     193
    192194    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    193195    out[i].Ncode = in[i].Ncode;
     
    206208
    207209  for (i = 0; i < Nvalues; i++) {
    208     out[i].M     = in[i].M;     
    209     out[i].dM    = in[i].dM;     
     210    out[i].M             = in[i].MpsfChp;     
     211    out[i].dM            = in[i].dMpsfChp;     
     212
    210213    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    211214    out[i].Ncode = in[i].Ncode;
     
    245248    out[i].apmifit          = in[i].apmifit;
    246249    out[i].dapmifit         = in[i].dapmifit;
    247     out[i].Mcal             = in[i].Mcal;
     250
     251    out[i].McalPSF          = in[i].Mcal;
     252    out[i].McalAPER         = in[i].Mcal;
    248253    out[i].dMcal            = in[i].dMcal;
    249     out[i].Xm               = in[i].Xm;
     254    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     255
    250256    out[i].photcode         = in[i].photcode;
    251257    out[i].exptime          = in[i].exptime;
     
    316322    out[i].apmifit          = in[i].apmifit;
    317323    out[i].dapmifit         = in[i].dapmifit;
    318     out[i].Mcal             = in[i].Mcal;
     324
     325    out[i].Mcal             = in[i].McalPSF;
    319326    out[i].dMcal            = in[i].dMcal;
    320     out[i].Xm               = in[i].Xm;
     327    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     328
    321329    out[i].photcode         = in[i].photcode;
    322330    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r39457 r40291  
    1717    out[i].M          = in[i].M;
    1818    out[i].dM         = in[i].dM;
    19     out[i].Mcal       = in[i].Mcal;
     19    out[i].McalPSF    = in[i].Mcal;
     20    out[i].McalAPER   = in[i].Mcal;
    2021
    2122    out[i].airmass    = in[i].airmass;
     
    6869    out[i].M          = in[i].M;
    6970    out[i].dM         = in[i].dM;
    70     out[i].Mcal       = in[i].Mcal;
     71    out[i].Mcal       = in[i].McalPSF;
    7172    out[i].airmass    = in[i].airmass;
    7273    out[i].az         = in[i].az;
     
    188189    dvo_secfilt_init (&out[i], SECFILT_RESET_ALL);
    189190
    190     out[i].M     = in[i].M;     
    191     out[i].dM    = in[i].dM;     
     191    out[i].MpsfChp     = in[i].M;     
     192    out[i].dMpsfChp    = in[i].dM;     
     193
    192194    out[i].Mchisq= pow (10.0, 0.01*in[i].Xm);     
    193195    out[i].Ncode = in[i].Ncode;
     
    206208
    207209  for (i = 0; i < Nvalues; i++) {
    208     out[i].M     = in[i].M;     
    209     out[i].dM    = in[i].dM;     
     210    out[i].M             = in[i].MpsfChp;     
     211    out[i].dM            = in[i].dMpsfChp;     
     212
    210213    out[i].Xm    = 100.0*log10(in[i].Mchisq);     
    211214    out[i].Ncode = in[i].Ncode;
     
    245248    out[i].apmifit          = in[i].apmifit;
    246249    out[i].dapmifit         = in[i].dapmifit;
    247     out[i].Mcal             = in[i].Mcal;
     250
     251    out[i].McalPSF          = in[i].Mcal;
     252    out[i].McalAPER         = in[i].Mcal;
    248253    out[i].dMcal            = in[i].dMcal;
    249     out[i].Xm               = in[i].Xm;
     254    out[i].McalChiSq        = pow(10.0, 0.01*in[i].Xm);
     255
    250256    out[i].photcode         = in[i].photcode;
    251257    out[i].exptime          = in[i].exptime;
     
    316322    out[i].apmifit          = in[i].apmifit;
    317323    out[i].dapmifit         = in[i].dapmifit;
    318     out[i].Mcal             = in[i].Mcal;
     324
     325    out[i].Mcal             = in[i].McalPSF;
    319326    out[i].dMcal            = in[i].dMcal;
    320     out[i].Xm               = in[i].Xm;
     327    out[i].Xm               = 100.0*log10(in[i].McalChiSq);
     328
    321329    out[i].photcode         = in[i].photcode;
    322330    out[i].exptime          = in[i].exptime;
  • trunk/Ohana/src/libdvo/src/dvo_image.c

    r40063 r40291  
    223223  if (db[0].format == DVO_FORMAT_PS1_V4)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V4");
    224224  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5");
     225  if (db[0].format == DVO_FORMAT_PS1_V6)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V6");
    225226  if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V5_LOAD");
    226227  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_REF");
     
    256257  int start_size = header->datasize;
    257258
    258   long A = time(NULL);
     259  int PID = getpid();
     260  long A = PID + time(NULL);
    259261  srand48(A);
    260262 
     
    321323  gfits_define_bintable_column (header, "E",    "APMIFIT",          "aperture correction",             "mag",               1.0, 0.0);
    322324  gfits_define_bintable_column (header, "E",    "DAPMIFIT",         "apmifit error",                   "mag",               1.0, 0.0);
    323   gfits_define_bintable_column (header, "E",    "MCAL",             "calibration mag",                 "mag",               1.0, 0.0);
     325  gfits_define_bintable_column (header, "E",    "MCAL_PSF",         "calibration mag for psfs",        "mag",               1.0, 0.0);
     326  gfits_define_bintable_column (header, "E",    "MCAL_APER",        "calibration mag for aper",        "mag",               1.0, 0.0);
    324327  gfits_define_bintable_column (header, "E",    "DMCAL",            "error on Mcal",                   "mag",               1.0, 0.0);
    325   gfits_define_bintable_column (header, "I",    "XM",               "image chisq",                     "10*log(value)",     1.0, 0.0);
     328  gfits_define_bintable_column (header, "E",    "XM",               "image chisq",                     "10*log(value)",     1.0, 0.0);
     329  gfits_define_bintable_column (header, "I",    "PADDING",          "filler for 8-byte boundaries,",   "",                  1.0, 0.0);
    326330  gfits_define_bintable_column (header, "I",    "PHOTCODE",         "identifier for CCD,",             "",                  1.0, 0.0);
    327331  gfits_define_bintable_column (header, "E",    "EXPTIME",          "exposure time",                   "seconds",           1.0, 0.0);
  • trunk/Ohana/src/libdvo/src/dvo_image_raw.c

    r40063 r40291  
    6060  if (db[0].format == DVO_FORMAT_PS1_V4)          ImageSize = sizeof(Image_PS1_V4);
    6161  if (db[0].format == DVO_FORMAT_PS1_V5)          ImageSize = sizeof(Image_PS1_V5);
     62  if (db[0].format == DVO_FORMAT_PS1_V6)          ImageSize = sizeof(Image_PS1_V6);
    6263  if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     ImageSize = sizeof(Image_PS1_V5_LOAD);
    6364  if (db[0].format == DVO_FORMAT_PS1_REF)         ImageSize = sizeof(Image_PS1_REF);
     
    9394  if (db[0].format == DVO_FORMAT_PS1_V4)          gfits_table_mkheader_Image_PS1_V4 (&db[0].theader);
    9495  if (db[0].format == DVO_FORMAT_PS1_V5)          gfits_table_mkheader_Image_PS1_V5 (&db[0].theader);
     96  if (db[0].format == DVO_FORMAT_PS1_V6)          gfits_table_mkheader_Image_PS1_V6 (&db[0].theader);
    9597  if (db[0].format == DVO_FORMAT_PS1_V5_LOAD)     gfits_table_mkheader_Image_PS1_V5_LOAD (&db[0].theader);
    9698  if (db[0].format == DVO_FORMAT_PS1_REF)         gfits_table_mkheader_Image_PS1_REF (&db[0].theader);
  • trunk/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r39670 r40291  
    381381
    382382  float Mraw = NAN;
     383  float Mcal = NAN;
    383384  switch (class) {
    384385    case MAG_CLASS_PSF:
    385386      Mraw = measure[0].M;
     387      Mcal = measure[0].McalPSF;
    386388      break;
    387389    case MAG_CLASS_KRON:
    388390      Mraw = measure[0].Mkron;
     391      Mcal = measure[0].McalAPER;
    389392      break;
    390393    case MAG_CLASS_APER:
    391394      Mraw = measure[0].Map;
     395      Mcal = measure[0].McalAPER;
    392396      break;
    393397    default:
     
    398402  }
    399403  float Mflat = isfinite(measure[0].Mflat) ? measure[0].Mflat : 0.0;
    400   float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal - Mflat;
     404  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - Mcal - Mflat;
    401405
    402406  /* for DEP, color must be made of PRI/SEC */
     
    479483      switch (class) {
    480484        case MAG_CLASS_PSF:
    481           Mave = secfilt[Ns].M;
     485          Mave = secfilt[Ns].MpsfChp;
    482486          break;
    483487        case MAG_CLASS_KRON:
    484           Mave = secfilt[Ns].Mkron;
     488          Mave = secfilt[Ns].MkronChp;
    485489          break;
    486490        case MAG_CLASS_APER:
    487           Mave = secfilt[Ns].Map;
     491          Mave = secfilt[Ns].MapChp;
    488492          break;
    489493        default:
     
    592596      switch (class) {
    593597        case MAG_CLASS_PSF:
    594           dMave = secfilt[Ns].dM;
     598          dMave = secfilt[Ns].dMpsfChp;
    595599          break;
    596600        case MAG_CLASS_KRON:
    597           dMave = secfilt[Ns].dMkron;
     601          dMave = secfilt[Ns].dMkronChp;
    598602          break;
    599603        case MAG_CLASS_APER:
    600           dMave = secfilt[Ns].dMap;
     604          dMave = secfilt[Ns].dMapChp;
    601605          break;
    602606        default:
     
    677681    Ns2 = photcodes[0].hashNsec[code[0].c2];
    678682 
    679     m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].M;
    680     m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].M;
     683    m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].MpsfChp;
     684    m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].MpsfChp;
    681685    mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
    682686    return (mc);
     
    694698  } else {
    695699    Ns = photcodes[0].hashNsec[color[0].code];
    696     m1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     700    m1 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    697701  }     
    698702
     
    708712  } else {
    709713    Ns = photcodes[0].hashNsec[color[0].code];
    710     m2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     714    m2 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    711715  }     
    712716  mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
     
    727731      switch (class) {
    728732        case MAG_CLASS_PSF:
    729           Mstdev = secfilt[Ns].Mstdev;
     733          Mstdev = secfilt[Ns].sMpsfChp;
    730734          break;
    731735        case MAG_CLASS_KRON:
    732           Mstdev = secfilt[Ns].sMkron;
     736          Mstdev = secfilt[Ns].sMkronChp;
    733737          break;
    734738        case MAG_CLASS_APER:
    735           Mstdev = secfilt[Ns].sMap;
     739          Mstdev = secfilt[Ns].sMapChp;
    736740          break;
    737741        default:
     
    10401044  } else {
    10411045    Ns = photcodes[0].hashNsec[code[0].code];
    1042     M1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     1046    M1 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    10431047  }     
    10441048
     
    10561060  } else {
    10571061    Ns = photcodes[0].hashNsec[code[0].code];
    1058     M2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     1062    M2 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    10591063  }     
    10601064 
     
    11301134
    11311135  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
    1132   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1133   float Moff = Mcal - ZERO_POINT + 8.9;
    1134   float Foff = 3630.8 * MagToFlux(Mcal);
     1136  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1137  float Moff = Mzpt - ZERO_POINT + 8.9;
     1138  float Foff = 3630.8 * MagToFlux(Mzpt);
    11351139  float Fcat = NAN;
    11361140  switch (class) {
     
    11581162
    11591163  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
    1160   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1161   float Moff = Mcal - ZERO_POINT + 8.9;
    1162   float Foff = 3630.8 * MagToFlux(Mcal);
     1164  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1165  float Moff = Mzpt - ZERO_POINT + 8.9;
     1166  float Foff = 3630.8 * MagToFlux(Mzpt);
    11631167  float Fcat = NAN;
    11641168  switch (class) {
     
    12031207
    12041208  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1209
     1210  // use Mcal APER for aperture-like data
     1211  float Mcal = (class == MAG_CLASS_PSF) ? measure[0].McalPSF : measure[0].McalAPER;
    12051212  float Mflat = isfinite(measure[0].Mflat) ? measure[0].Mflat : 0.0;
    1206   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal - Mflat;
    1207   float Moff = Mcal - ZERO_POINT + 8.9;
    1208   float Foff = 3630.8 * MagToFlux(Mcal);
     1213
     1214  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - Mcal - Mflat;
     1215  float Moff = Mzpt - ZERO_POINT + 8.9;
     1216  float Foff = 3630.8 * MagToFlux(Mzpt);
    12091217  float Fcat = NAN;
    12101218  switch (class) {
     
    12891297      switch (class) {
    12901298        case MAG_CLASS_PSF:
    1291           Fave = MagToFlux(secfilt[Ns].M - 8.9);
     1299          Fave = MagToFlux(secfilt[Ns].MpsfChp - 8.9);
    12921300          break;
    12931301        case MAG_CLASS_KRON:
    1294           Fave = MagToFlux(secfilt[Ns].Mkron - 8.9);
     1302          Fave = MagToFlux(secfilt[Ns].MkronChp - 8.9);
    12951303          break;
    12961304        case MAG_CLASS_APER:
    1297           Fave = MagToFlux(secfilt[Ns].Map - 8.9);
     1305          Fave = MagToFlux(secfilt[Ns].MapChp - 8.9);
    12981306          break;
    12991307        default:
     
    13501358      switch (class) {
    13511359        case MAG_CLASS_PSF:
    1352           dFave = secfilt[Ns].dM * MagToFlux(secfilt[Ns].M - 8.9);
     1360          dFave = secfilt[Ns].dMpsfChp * MagToFlux(secfilt[Ns].MpsfChp - 8.9);
    13531361          break;
    13541362        case MAG_CLASS_KRON:
    1355           dFave = secfilt[Ns].dMkron * MagToFlux(secfilt[Ns].Mkron - 8.9);
     1363          dFave = secfilt[Ns].dMkronChp * MagToFlux(secfilt[Ns].MkronChp - 8.9);
    13561364          break;
    13571365        case MAG_CLASS_APER:
    1358           dFave = secfilt[Ns].dMap * MagToFlux(secfilt[Ns].Map - 8.9);
     1366          dFave = secfilt[Ns].dMapChp * MagToFlux(secfilt[Ns].MapChp - 8.9);
    13591367          break;
    13601368        default:
     
    14701478
    14711479  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
    1472   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1473   float Moff = Mcal - ZERO_POINT + 8.9;
    1474   float Foff = 3630.8 * MagToFlux(Mcal);
     1480  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1481  float Moff = Mzpt - ZERO_POINT + 8.9;
     1482  float Foff = 3630.8 * MagToFlux(Mzpt);
    14751483
    14761484  // use dFlux if we can, but use dMag if we must:
     
    15161524
    15171525  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
    1518   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    1519   float Moff = Mcal - ZERO_POINT + 8.9;
    1520   float Foff = 3630.8 * MagToFlux(Mcal);
     1526  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     1527  float Moff = Mzpt - ZERO_POINT + 8.9;
     1528  float Foff = 3630.8 * MagToFlux(Mzpt);
    15211529
    15221530  // use dFlux if we can, but use dMag if we must:
     
    15791587
    15801588  // measure.M has the static ZERO_POINT (25.0) applied, but not measure.Flux
     1589  // XXX fix this too:
    15811590  float Mflat = isfinite(measure[0].Mflat) ? measure[0].Mflat : 0.0;
    1582   float Mcal = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal - Mflat;
    1583   float Moff = Mcal - ZERO_POINT + 8.9;
    1584   float Foff = 3630.8 * MagToFlux(Mcal);
     1591  float Mcal = (class == MAG_CLASS_PSF) ? measure[0].McalPSF : measure[0].McalAPER;
     1592
     1593  float Mzpt = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - Mcal - Mflat;
     1594  float Moff = Mzpt - ZERO_POINT + 8.9;
     1595  float Foff = 3630.8 * MagToFlux(Mzpt);
    15851596
    15861597  // use dFlux if we can, but use dMag if we must:
     
    16491660      break;
    16501661    case MAG_CLASS_KRON:
    1651       // Mraw = measure[0].Mkron;
     1662      Mraw = measure[0].Mkron;
    16521663      break;
    16531664    case MAG_CLASS_APER:
    1654       // Mraw = measure[0].Map;
     1665      // Mraw = measure[0].Map; // MeasureTiny does not have Map
    16551666      break;
    16561667    default:
     
    16771688      break;
    16781689    case MAG_CLASS_KRON:
    1679       // Mraw = measure[0].Mkron;
     1690      Mraw = measure[0].Mkron;
    16801691      break;
    16811692    case MAG_CLASS_APER:
    1682       // Mraw = measure[0].Map;
     1693      // Mraw = measure[0].Map; // MeasureTiny does not have Map
    16831694      break;
    16841695    default:
     
    17061717      break;
    17071718    case MAG_CLASS_KRON:
    1708       // Mraw = measure[0].Mkron;
     1719      Mraw = measure[0].Mkron;
    17091720      break;
    17101721    case MAG_CLASS_APER:
    1711       // Mraw = measure[0].Map;
     1722      // Mraw = measure[0].Map; // MeasureTiny does not have Map
    17121723      break;
    17131724    default:
     
    17421753
    17431754  float Mraw = NAN;
     1755  float Mcal = NAN;
    17441756  switch (class) {
    17451757    case MAG_CLASS_PSF:
    17461758      Mraw = measure[0].M;
     1759      Mcal = measure[0].McalPSF;
    17471760      break;
    17481761    case MAG_CLASS_KRON:
    1749       // Mraw = measure[0].Mkron;
     1762      Mraw = measure[0].Mkron;
     1763      Mcal = measure[0].McalAPER;
    17501764      break;
    17511765    case MAG_CLASS_APER:
    1752       // Mraw = measure[0].Map;
     1766      // Mraw = measure[0].Map; // MeasureTiny does not have Map
     1767      // Mcal = measure[0].McalAPER;
    17531768      break;
    17541769    default:
     
    17591774  }
    17601775  float Mflat = isfinite(measure[0].Mflat) ? measure[0].Mflat : 0.0;
    1761   float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal - Mflat;
     1776  float Mcat = Mraw - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - Mcal - Mflat;
    17621777
    17631778  /* for DEP, color must be made of PRI/SEC */
     
    17991814        break;
    18001815      case MAG_CLASS_KRON:
    1801         // Mraw = thisone[0].Mkron;
     1816        Mraw = thisone[0].Mkron;
    18021817        break;
    18031818      case MAG_CLASS_APER:
    1804         // Mraw = thisone[0].Map;
     1819        // Mraw = thisone[0].Map; // MeasureTiny does not have Map
    18051820        break;
    18061821      default:
     
    18401855      switch (class) {
    18411856        case MAG_CLASS_PSF:
    1842           Mave = secfilt[Ns].M;
     1857          Mave = secfilt[Ns].MpsfChp;
    18431858          break;
    18441859        case MAG_CLASS_KRON:
    1845           Mave = secfilt[Ns].Mkron;
     1860          Mave = secfilt[Ns].MkronChp;
    18461861          break;
    18471862        case MAG_CLASS_APER:
    1848           Mave = secfilt[Ns].Map;
     1863          Mave = secfilt[Ns].MapChp;
    18491864          break;
    18501865        default:
     
    19271942    Ns2 = photcodes[0].hashNsec[code[0].c2];
    19281943 
    1929     m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].M;
    1930     m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].M;
     1944    m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].MpsfChp;
     1945    m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].MpsfChp;
    19311946    mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
    19321947    return (mc);
     
    19441959  } else {
    19451960    Ns = photcodes[0].hashNsec[color[0].code];
    1946     m1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     1961    m1 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    19471962  }     
    19481963
     
    19581973  } else {
    19591974    Ns = photcodes[0].hashNsec[color[0].code];
    1960     m2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     1975    m2 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    19611976  }     
    19621977  mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
     
    19731988
    19741989  Ns = photcodes[0].hashNsec[code[0].code];
    1975   dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
     1990  dM  = (Ns == -1) ? NAN : secfilt[Ns].dMpsfChp;
    19761991  return (dM);
    19771992}
     
    20102025  } else {
    20112026    Ns = photcodes[0].hashNsec[code[0].code];
    2012     M1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     2027    M1 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    20132028  }     
    20142029
     
    20262041  } else {
    20272042    Ns = photcodes[0].hashNsec[code[0].code];
    2028     M2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     2043    M2 = (Ns == -1) ? NAN : secfilt[Ns].MpsfChp;
    20292044  }     
    20302045 
  • trunk/Ohana/src/libdvo/src/dvo_tiny_values.c

    r39457 r40291  
    1919  measureT[0].D          = measure[0].D;
    2020  measureT[0].M          = measure[0].M;
    21   measureT[0].Mcal       = measure[0].Mcal;
     21  measureT[0].Mkron      = measure[0].Mkron;
     22  measureT[0].McalPSF    = measure[0].McalPSF;
     23  measureT[0].McalAPER   = measure[0].McalAPER;
    2224  measureT[0].dM         = measure[0].dM;
    2325  measureT[0].airmass    = measure[0].airmass;
  • trunk/Ohana/src/libohana/include/ohana.h

    r39457 r40291  
    485485/* in bisection.c */
    486486int ohana_bisection_double (double *values, int Nvalues, double threshold);
     487int ohana_bisection_int (int *values, int Nvalues, int threshold);
    487488
    488489unsigned int sprintf_float (char *output, float value);
  • trunk/Ohana/src/libohana/include/ohana_sort.h

    r38986 r40291  
    6868void fsort (float *value, int N);
    6969void isort (int *value, int N);
     70void llsort (long long int *value, int N);
    7071
    7172void dsortpair (double *X, double *Y, int N);
  • trunk/Ohana/src/libohana/src/bisection.c

    r38459 r40291  
    3232  return (N);
    3333}
     34
     35// return the index of the last value < threshold
     36int ohana_bisection_int (int *values, int Nvalues, int threshold) {
     37
     38  int Nlo = 0;
     39  int Nhi = Nvalues - 1;
     40
     41  if (Nvalues < 1) return (-1);
     42  if (values[Nlo] > threshold) return (-1);
     43
     44  if (Nvalues < 2) return (0);
     45  if (values[Nhi] < threshold) return (Nhi);
     46
     47  int N;
     48  while (Nhi - Nlo > 4) {
     49    N = 0.5*(Nlo + Nhi);
     50    if (values[N] < threshold) {
     51      Nlo = MAX(N, 0);
     52    } else {
     53      Nhi = MIN(N + 1, Nvalues - 1);
     54    }
     55  }
     56  // values[Nlo] < threshold
     57  // values[Nhi] >= threshold
     58
     59  for (N = Nlo; N < Nhi; N++) {
     60    if (values[N] >= threshold) {
     61      return (N-1);
     62    }
     63  }
     64  return (N);
     65}
  • trunk/Ohana/src/libohana/src/isolate_elements.c

    r40013 r40291  
    171171  // order matches convert_to_RPN.c
    172172  if (!strncmp (c, "?",  1)) return (TRUE);
    173   if (!strncmp (c, ":",  1)) return (TRUE);
     173
     174  // if (!strncmp (c, ":",  1)) return (TRUE);
     175
     176  // do not include : in this list: an unisolated colon acts as a modifier
    174177
    175178  if (!strncmp (c, "^",  1)) return (TRUE);
  • trunk/Ohana/src/libohana/src/sorts.c

    r38986 r40291  
    3030
    3131# define SWAPFUNC(A,B){ int tmp = value[A]; value[A] = value[B]; value[B] = tmp; }
     32# define COMPARE(A,B)(value[A] < value[B])
     33
     34  OHANA_SORT (N, COMPARE, SWAPFUNC);
     35
     36# undef SWAPFUNC
     37# undef COMPARE
     38
     39}
     40
     41void llsort (long long int *value, int N) {
     42
     43# define SWAPFUNC(A,B){ long long int tmp = value[A]; value[A] = value[B]; value[B] = tmp; }
    3244# define COMPARE(A,B)(value[A] < value[B])
    3345
  • trunk/Ohana/src/markrock/src/find_slow_rocks.c

    r2490 r40291  
    6969        RD_to_XY (&X1[j], &Y1[j], R1[j], D1[j], &catstats[0].coords);
    7070        T1[j] = catalog[0].measure[m+j].t;
    71         M1[j] = catalog[0].measure[m+j].M - catalog[0].measure[m+j].Mcal;
     71        M1[j] = catalog[0].measure[m+j].M - catalog[0].measure[m+j].McalPSF;
    7272      }
    7373      dt = T1[1] - T1[0];
     
    8686          RD_to_XY (&X, &Y, R, D, &catstats[0].coords);
    8787          T = catalog[0].measure[m+j].t;
    88           M = catalog[0].measure[m+j].M - catalog[0].measure[m+j].Mcal;
     88          M = catalog[0].measure[m+j].M - catalog[0].measure[m+j].McalPSF;
    8989          if (T1[0] == T) continue;
    9090          if (T1[1] == T) continue;
  • trunk/Ohana/src/opihi/cmd.astro/fitplx.c

    r39610 r40291  
    7777  double *dD = dDvec->elements.Flt;
    7878
    79   int *mask = NULL;
     79  opihi_int *mask = NULL;
    8080  if (mvec) {
    8181    mask = mvec->elements.Int;
     
    380380}
    381381
    382 int PlxSetMeanEpoch (double *R, double *D, double *T, double *Rmean, double *Dmean, double *Tmean, int *mask, int Ntotal) {
     382int PlxSetMeanEpoch (double *R, double *D, double *T, double *Rmean, double *Dmean, double *Tmean, opihi_int *mask, int Ntotal) {
    383383
    384384  int i;
     
    413413
    414414// generate the fit values (projected X,Y; parallax factors;
    415 int PlxSetEpochPosition (PlxFitData *fitdata, double *R, double *D, double *dR, double *dD, double *T, int *mask, int Ntotal, Coords *coords, double Tmean) {
     415int PlxSetEpochPosition (PlxFitData *fitdata, double *R, double *D, double *dR, double *dD, double *T, opihi_int *mask, int Ntotal, Coords *coords, double Tmean) {
    416416
    417417  int i;
     
    464464# define MAX_REJECT 0.1
    465465
    466 int PlxOutlierClip (PlxFitData *fitdata, int *mask, int Noutlier, float dPsigMax, Vector *dPvec, int VERBOSE) {
     466int PlxOutlierClip (PlxFitData *fitdata, opihi_int *mask, int Noutlier, float dPsigMax, Vector *dPvec, int VERBOSE) {
    467467
    468468  int i, n;
  • trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c

    r39926 r40291  
    8181  double *dD = dDvec->elements.Flt;
    8282
    83   int *mask = NULL;
     83  opihi_int *mask = NULL;
    8484  if (mvec) {
    8585    mask = mvec->elements.Int;
     
    109109  for (i = 0; (VERBOSE == 2) && (i < fitdata.Npts); i++) {
    110110    int n = fitdata.index[i];
    111     int maskValue = mask ? mask[n] : 1;
    112     fprintf (stderr, "%f %f : %f %d : %f %f %f\n", R[n], D[n], T[n], maskValue, fitdata.t[i], fitdata.X[i], fitdata.Y[i]);
     111    opihi_int maskValue = mask ? mask[n] : 1;
     112    fprintf (stderr, "%f %f : %f "OPIHI_INT_FMT" : %f %f %f\n", R[n], D[n], T[n], maskValue, fitdata.t[i], fitdata.X[i], fitdata.Y[i]);
    113113  }
    114114
     
    150150     
    151151      if (VERBOSE == 2) {
    152           fprintf (stderr, "%f %f : %f %d : %f %f %f : %f %f %f %f\n", R[n], D[n], T[n], mask[n], fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.Wx[i], fitdata.Wy[i], Sum_Wx, Sum_Wy);
     152          fprintf (stderr, "%f %f : %f "OPIHI_INT_FMT" : %f %f %f : %f %f %f %f\n", R[n], D[n], T[n], mask[n], fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.Wx[i], fitdata.Wy[i], Sum_Wx, Sum_Wy);
    153153      }
    154154    }
  • trunk/Ohana/src/opihi/cmd.astro/fitpm.c

    r39228 r40291  
    5050  double *dD = dDvec->elements.Flt;
    5151
    52   int *mask = NULL;
     52  opihi_int *mask = NULL;
    5353  if (mvec) {
    5454    mask = mvec->elements.Int;
  • trunk/Ohana/src/opihi/cmd.astro/fitpm_irls.c

    r39596 r40291  
    5858  double *dD = dDvec->elements.Flt;
    5959
    60   int *mask = NULL;
     60  opihi_int *mask = NULL;
    6161  if (mvec) {
    6262    mask = mvec->elements.Int;
  • trunk/Ohana/src/opihi/cmd.astro/star.c

    r36679 r40291  
    33int star (int argc, char **argv) {
    44
    5   int x, y, N, dx, Nborder;
     5  int x, y, N, Nborder;
    66  double max;
    77  Buffer *buf;
     
    3333  }
    3434 
     35  int dx = 11;
     36  int dy = 11;
     37  int BOX = FALSE;
     38  if ((N = get_argument (argc, argv, "-box"))) {
     39    remove_argument (N, &argc, argv);
     40    dx  = atoi(argv[N]);
     41    remove_argument (N, &argc, argv);
     42    dy  = atoi(argv[N]);
     43    remove_argument (N, &argc, argv);
     44    BOX = TRUE;
     45  }
     46
    3547  if ((argc != 4) && (argc != 5)) {
    36     gprint (GP_ERR, "USAGE: star (buffer) x y [dx] [-border N] [-sat cnts]\n");
     48    gprint (GP_ERR, "USAGE: star (buffer) x y [dx] [-border N] [-sat cnts] [-box dx dy]\n");
    3749    gprint (GP_ERR, " dx is the aperture diameter, but is adjusted up to the next odd number\n");
    3850    return (FALSE);
     
    4052  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    4153
    42   dx = 11;
    4354  x = atof (argv[2]);
    4455  y = atof (argv[3]);
     
    4758  }
    4859
    49   get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max, VERBOSE);
     60  if (BOX) {
     61    get_box_stats (&buf[0].matrix, x, y, dx, dy, Nborder, max, VERBOSE);
     62  } else {
     63    get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max, VERBOSE);
     64  }
    5065 
    5166  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r40165 r40291  
    155155$(SRC)/type.$(ARCH).o              \
    156156$(SRC)/uniq.$(ARCH).o              \
     157$(SRC)/uniqpair.$(ARCH).o                  \
    157158$(SRC)/unsign.$(ARCH).o            \
    158159$(SRC)/vbin.$(ARCH).o              \
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r40165 r40291  
    141141int tvcontour        PROTO((int, char **));
    142142int tvgrid           PROTO((int, char **));
    143 int opihi_type             PROTO((int, char **));
     143int opihi_type       PROTO((int, char **));
    144144int uniq             PROTO((int, char **));
     145int uniqpair         PROTO((int, char **));
    145146int unsign           PROTO((int, char **));
    146147int vbin             PROTO((int, char **));
     
    325326  {1, "ungridify",    ungridify,        "convert image region to vector triplet"},
    326327  {1, "uniq",         uniq,             "create a uniq vector subset from a vector"},
     328  {1, "uniqpair",     uniqpair,         "create a uniq vector subset from a pair of vectors, saving duplicates if desired"},
    327329  {1, "unsign",       unsign,           "toggle the UNSIGN status"},
    328330  {1, "vbin",         vbin,             "rebin vector data by a factor of N"},
  • trunk/Ohana/src/opihi/cmd.data/limits.c

    r31160 r40291  
    33int limits (int argc, char **argv) {
    44
    5   int N, APPLY, dX, dY;
     5  int N, dX, dY;
    66  int kapa;
    7   char *name;
    87  Graphdata graphmode;
    98  Vector *xvec, *yvec;
     
    1110  xvec = yvec = NULL;
    1211
    13   APPLY = FALSE;
     12  float minLimitX = NAN;
     13  float minLimitY = NAN;
     14  float maxLimitX = NAN;
     15  float maxLimitY = NAN;
     16  float delLimitX = NAN;
     17  float delLimitY = NAN;
     18
     19  if ((N = get_argument (argc, argv, "-minX"))) {
     20    remove_argument (N, &argc, argv);
     21    minLimitX = atof (argv[N]);
     22    remove_argument (N, &argc, argv);
     23  }
     24  if ((N = get_argument (argc, argv, "-maxX"))) {
     25    remove_argument (N, &argc, argv);
     26    maxLimitX = atof (argv[N]);
     27    remove_argument (N, &argc, argv);
     28  }
     29  if ((N = get_argument (argc, argv, "-delX"))) {
     30    if (!isnan(minLimitX) || !isnan(maxLimitX)) {
     31      gprint (GP_ERR, "-minX & -maxX cannot be mixed with -delX\n");
     32      return (FALSE);
     33    }
     34    remove_argument (N, &argc, argv);
     35    delLimitX = atof (argv[N]);
     36    remove_argument (N, &argc, argv);
     37  }
     38  if ((N = get_argument (argc, argv, "-minY"))) {
     39    remove_argument (N, &argc, argv);
     40    minLimitY = atof (argv[N]);
     41    remove_argument (N, &argc, argv);
     42  }
     43  if ((N = get_argument (argc, argv, "-maxY"))) {
     44    remove_argument (N, &argc, argv);
     45    maxLimitY = atof (argv[N]);
     46    remove_argument (N, &argc, argv);
     47  }
     48  if ((N = get_argument (argc, argv, "-delY"))) {
     49    if (!isnan(minLimitY) || !isnan(maxLimitY)) {
     50      gprint (GP_ERR, "-minY & -maxY cannot be mixed with -delY\n");
     51      return (FALSE);
     52    }
     53    remove_argument (N, &argc, argv);
     54    delLimitY = atof (argv[N]);
     55    remove_argument (N, &argc, argv);
     56  }
     57
     58  int APPLY = FALSE;
    1459  if ((N = get_argument (argc, argv, "-a"))) {
    1560    remove_argument (N, &argc, argv);
    1661    APPLY = TRUE;
    1762  }
    18   name = NULL;
     63  char *name = NULL;
    1964  if ((N = get_argument (argc, argv, "-n"))) {
    2065    remove_argument (N, &argc, argv);
     
    2267    remove_argument (N, &argc, argv);
    2368  }
     69
    2470  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
    2571  FREE (name);
     
    97143 success:
    98144  SetLimits (xvec, yvec, &graphmode);
     145
     146  if (!isnan(minLimitX)) graphmode.xmin = MIN (minLimitX, graphmode.xmin);
     147  if (!isnan(maxLimitX)) graphmode.xmax = MAX (maxLimitX, graphmode.xmax);
     148  if (!isnan(minLimitY)) graphmode.ymin = MIN (minLimitY, graphmode.ymin);
     149  if (!isnan(maxLimitY)) graphmode.ymax = MAX (maxLimitY, graphmode.ymax);
     150
     151  if (!isnan(delLimitX)) {
     152    float delta = graphmode.xmax - graphmode.xmin;
     153    if (fabs(delLimitX) > fabs(delta)) {
     154      float midpt = 0.5*(graphmode.xmax + graphmode.xmin);
     155      graphmode.xmax = midpt + 0.5*delLimitX;
     156      graphmode.xmin = midpt - 0.5*delLimitX;
     157    }
     158  }
     159  if (!isnan(delLimitY)) {
     160    float delta = graphmode.ymax - graphmode.ymin;
     161    if (fabs(delLimitY) > fabs(delta)) {
     162      float midpt = 0.5*(graphmode.ymax + graphmode.ymin);
     163      graphmode.ymax = midpt + 0.5*delLimitY;
     164      graphmode.ymin = midpt - 0.5*delLimitY;
     165    }
     166  }
     167
    99168  if (APPLY) KapaSetLimits (kapa, &graphmode);
    100169  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/print_vectors.c

    r37049 r40291  
    44
    55  Vector **vec;
    6   int i, j;
     6  int i, j, N;
     7
     8  int START_VALUE = 0;
     9  if ((N = get_argument (argc, argv, "-s"))) {
     10    remove_argument (N, &argc, argv);
     11    START_VALUE = atoi (argv[N]);
     12    remove_argument (N, &argc, argv);
     13  }
     14
     15  int END_VALUE = -1;
     16  if ((N = get_argument (argc, argv, "-e"))) {
     17    remove_argument (N, &argc, argv);
     18    END_VALUE = atoi (argv[N]);
     19    remove_argument (N, &argc, argv);
     20  }
    721
    822  if (argc < 2) {
     
    2741  }
    2842
    29   for (j = 0; j < MaxLen; j++) {
     43  // start and end may be 0 - N (truncated to N) or may be negative, in which case it refers to
     44  // distance from the end (just like vector[-5])
     45  START_VALUE = (START_VALUE < 0) ? MaxLen + START_VALUE + 1 : MIN (START_VALUE, MaxLen);
     46  START_VALUE = MAX (0, START_VALUE);
     47
     48  END_VALUE = (END_VALUE < 0) ? MaxLen + END_VALUE + 1 : MIN (END_VALUE, MaxLen);
     49  END_VALUE = MAX (0, END_VALUE);
     50
     51  for (j = START_VALUE; j < END_VALUE; j++) {
    3052    for (i = 0; i < Nvec; i++) {
    3153      if (j >= vec[i][0].Nelements) {
     
    3557          gprint (GP_LOG, "%f ", vec[i][0].elements.Flt[j]);
    3658        } else {
    37           gprint (GP_LOG, "%d ", vec[i][0].elements.Int[j]);
     59          gprint (GP_LOG, OPIHI_INT_FMT" ", vec[i][0].elements.Int[j]);
    3860        }
    3961      }
  • trunk/Ohana/src/opihi/cmd.data/reindex.c

    r39227 r40291  
    4747        continue;
    4848      }
    49       if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
     49      if (*vx > Nmax) ESCAPE("unexpected value in index: "OPIHI_INT_FMT" (%d)\n", *vx, i);
    5050      ovec[0].elements.Flt[Npts] = vi[*vx];
    5151      Npts++;
     
    6767        continue;
    6868      }
    69       if (*vx > Nmax) ESCAPE("unexpected value in index: %d (%d)\n", *vx, i);
     69      if (*vx > Nmax) ESCAPE("unexpected value in index: "OPIHI_INT_FMT" (%d)\n", *vx, i);
    7070      ovec[0].elements.Int[Npts] = vi[*vx];
    7171      Npts++;
  • trunk/Ohana/src/opihi/cmd.data/test/periodogram-fm.sh

    r40165 r40291  
    5555
    5656 periodogram_fm t f df 5 50 period power
    57 #periodogram t f 5 50 period power
    5857
    5958 # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    8887
    8988 periodogram_fm t f df 1 10 period power
    90 #periodogram t f 1 10 period power
    9189
    9290 # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    9795 if (abs ($peakpos - $P) > 0.05)
    9896   $PASS = 0
     97 end
     98
     99  if ($PLOT)
     100  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
    99101 end
    100102end
     
    117119
    118120 periodogram_fm t f df 2 30 period power
    119 #periodogram t f 2 30 period power
    120121
    121122#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    126127 if (abs ($peakpos - $P) > 0.05)
    127128   $PASS = 0
     129 end
     130
     131 if ($PLOT)
     132  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
    128133 end
    129134end
     
    145150 set df = 0.01 + zero(f)
    146151
    147  periodogram_fm t f 2 30 period power
     152 periodogram_fm t f df 2 30 period power
    148153
    149154#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    155160   $PASS = 0
    156161 end
    157 end
    158 
    159 # test using random samples, offset start, non-zero DC, some noise
     162
     163 if ($PLOT)
     164  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
     165 end
     166end
     167
     168# test using 300 random samples, offset start, non-zero DC, some noise
    160169macro test6
    161170 $PASS = 1
     
    178187 set df = 0.01 + zero(f)
    179188
    180  periodogram_fm t f 2 30 period power
     189 periodogram_fm t f df 2 30 period power
    181190
    182191#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    188197   $PASS = 0
    189198 end
    190 end
    191 
    192 # test using fewer random samples, offset start, non-zero DC, some noise
     199
     200 if ($PLOT)
     201  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
     202 end
     203end
     204
     205# test using 100 fewer random samples, offset start, non-zero DC, some noise
    193206macro test7
    194207 $PASS = 1
     
    211224 set df = 0.01 + zero(f)
    212225
    213  periodogram_fm t f 2 30 period power
     226 periodogram_fm t f df 2 30 period power
    214227
    215228#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    221234   $PASS = 0
    222235 end
    223 end
    224 
    225 # test using fewer random samples, high frequency, non-zero DC, some noise
     236
     237 if ($PLOT)
     238  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
     239 end
     240end
     241
     242# test using Ndays random samples, RR Lyrae-sized light curves (0.7 mag),
     243# optional noise level
    226244macro test8
    227  if ($0 != 2)
    228    echo "USAGE: test8: Ndays")
     245 if ($0 != 4)
     246   echo "USAGE: test8: Period Ndays (df)"
    229247   break
    230248 end
    231249 
    232250 local Ndays
    233  $Ndays = $1
    234 
    235  $PASS = 1
    236  break -auto off
    237 
    238  local P PI
    239  $PI = 3.14159265359
    240  $P  = 0.8*rnd(0) + 0.2
     251 $P = $1
     252 $Ndays = $2
     253 $dM = $3
     254
     255 $PASS = 1
     256 break -auto off
     257
     258 local PI
     259 $PI = 3.14159265359
    241260 $trueP = $P
    242261
     
    246265
    247266 # t is a time in days, but we always have 4 within 1 hour:
    248  set t0 = int(100 * rnd(x))
    249  set dtx = (3/24) * rnd(x)
    250  set t0 = t0 + dtx
     267 set tday = int(100 * rnd(x)); # choose Ndays random days between 0 and 100
     268 set dtx = (3/24) * rnd(x);  # choose a starting time within that night
     269 set t0 = tday + dtx
    251270
    252271 set dt1 = (15.0 / 1440) * rnd(x) + ( 0 + 7.5) / 1440
     
    260279 set tmp = t0 + dt3; concat tmp t
    261280
    262  set fraw = sin(2*$PI*t/$P) + 0.5
     281 set fraw = 0.75*sin(2*$PI*t/$P)
    263282
    264283 # 0.05 : peakpos = 14.95
    265284 # 0.10 : peakpos = 15.04 (
    266  gaussdev df t[] 0.0 0.25
     285 gaussdev df t[] 0.0 $dM
    267286 set f = fraw + df
    268  set df = 0.01 + zero(f)
    269 
    270  periodogram_fm t f 0.1 2.0 period power
     287 set df = $dM + zero(f)
     288
     289 periodogram_fm t f df 0.1 20.0 period power
    271290
    272291#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     
    278297   $PASS = 0
    279298 end
    280 end
     299 if ($PLOT)
     300  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
     301 end
     302end
     303
     304# test using Ndays random samples, RR Lyrae-sized light curves (0.7 mag),
     305# optional noise level
     306# compare periodogram and periodogram_fm
     307macro test9
     308 if ($0 != 4)
     309   echo "USAGE: test8: Period Ndays (df)"
     310   break
     311 end
     312 
     313 local Ndays
     314 $P = $1
     315 $Ndays = $2
     316 $dM = $3
     317
     318 $PASS = 1
     319 break -auto off
     320
     321 local PI
     322 $PI = 3.14159265359
     323 $trueP = $P
     324
     325 delete -q x t f period power
     326
     327 create x 0 $Ndays
     328
     329 # t is a time in days, but we always have 4 within 1 hour:
     330 set tday = int(100 * rnd(x)); # choose Ndays random days between 0 and 100
     331 set dtx = (3/24) * rnd(x);  # choose a starting time within that night
     332 set t0 = tday + dtx
     333
     334 set dt1 = (15.0 / 1440) * rnd(x) + ( 0 + 7.5) / 1440
     335 set dt2 = (15.0 / 1440) * rnd(x) + (15 + 7.5) / 1440
     336 set dt3 = (15.0 / 1440) * rnd(x) + (30 + 7.5) / 1440
     337
     338 delete -q t
     339 concat t0 t
     340 set tmp = t0 + dt1; concat tmp t
     341 set tmp = t0 + dt2; concat tmp t
     342 set tmp = t0 + dt3; concat tmp t
     343
     344 set fraw = 0.75*sin(2*$PI*t/$P)
     345
     346 # 0.05 : peakpos = 14.95
     347 # 0.10 : peakpos = 15.04 (
     348 gaussdev df t[] 0.0 $dM
     349 set f = fraw + df
     350 set df = $dM + zero(f)
     351
     352 periodogram_fm t f df 0.1 20.0 period_fm power_fm
     353 periodogram t f 0.1 20.0 period power
     354
     355#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     356#  lim -n 1 period power; clear; box; plot period power
     357
     358 peak -q period_fm power_fm
     359 $peakval_fm = $peakval
     360
     361 peak -q period power
     362 vstat -q power
     363 set power = power / $MAX
     364
     365# if (abs ($peakpos - $P) > 0.05)
     366#   $PASS = 0
     367# end
     368
     369 set freq = 1 / period
     370 set freq_fm = 1 / period_fm
     371 $Freq = 1 / $P
     372
     373 if ($PLOT)
     374  if (1)
     375    lim period power; clear; box
     376    line -c red70 -lw 3 $P 0 to $P $peakval_fm;
     377    plot period power -x line -c grey70 -lw 2
     378    plot period_fm power_fm -x line -c black
     379  else
     380    lim freq power; clear; box
     381    line -c red70 -lw 3 $Freq 0 to $Freq 1.0
     382    plot freq power -x line -c grey70 -lw 2
     383    plot freq_fm power_fm -x line -c black
     384  end
     385 end
     386end
     387
     388
     389# test using Ndays random samples, RR Lyrae-sized light curves (0.7 mag),
     390# optional noise level
     391# compare periodogram and periodogram_fm
     392macro test10
     393 if ($0 != 4)
     394   echo "USAGE: test8: Period Ndays (df)"
     395   break
     396 end
     397 
     398 local Ndays
     399 $P = $1
     400 $Ndays = $2
     401 $dM = $3
     402
     403 $PASS = 1
     404 break -auto off
     405
     406 local PI
     407 $PI = 3.14159265359
     408 $trueP = $P
     409
     410 delete -q x t f period power
     411
     412 create x 0 $Ndays
     413
     414 # t is a time in days, but we always have 4 within 1 hour:
     415 set tday = int(100 * rnd(x)); # choose Ndays random days between 0 and 100
     416 set dtx = (3/24) * rnd(x);  # choose a starting time within that night
     417 set t0 = tday + dtx
     418
     419 set dt1 = (15.0 / 1440) * rnd(x) + ( 0 + 7.5) / 1440
     420 set dt2 = (15.0 / 1440) * rnd(x) + (15 + 7.5) / 1440
     421 set dt3 = (15.0 / 1440) * rnd(x) + (30 + 7.5) / 1440
     422
     423 delete -q t
     424 concat t0 t
     425 set tmp = t0 + dt1; concat tmp t
     426 set tmp = t0 + dt2; concat tmp t
     427 set tmp = t0 + dt3; concat tmp t
     428
     429 set fraw = 0.75*sin(2*$PI*t/$P)
     430
     431 # 0.05 : peakpos = 14.95
     432 # 0.10 : peakpos = 15.04 (
     433 gaussdev df t[] 0.0 $dM
     434 set f = fraw + df
     435 set df = $dM + zero(f)
     436
     437 periodogram_fm t f df 0.05 20.0 period_fm power_fm
     438
     439 gaussdev df t[] 0.0 $dM
     440 set Fo = df
     441 periodogram_fm t Fo df 0.05 20.0 period power
     442
     443#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     444#  lim -n 1 period power; clear; box; plot period power
     445
     446 peak -q period_fm power_fm
     447 $peakval_fm = $peakval
     448
     449 peak -q period power
     450
     451# if (abs ($peakpos - $P) > 0.05)
     452#   $PASS = 0
     453# end
     454
     455 set freq = 1 / period
     456 set freq_fm = 1 / period_fm
     457 $Freq = 1 / $P
     458
     459 if ($PLOT)
     460  if (1)
     461    lim period_fm power_fm; clear; box
     462    line -c red70 -lw 3 $P 0 to $P $peakval_fm;
     463    plot period power -x line -c grey70 -lw 2
     464    plot period_fm power_fm -x line -c black
     465  else
     466    lim freq power; clear; box
     467    line -c red70 -lw 3 $Freq 0 to $Freq 1.0
     468    plot freq power -x line -c grey70 -lw 2
     469    plot freq_fm power_fm -x line -c black
     470  end
     471 end
     472end
     473
     474# we have time (MJD) and mag
     475# we generate the folded lightcure and measure sigma relative to the smoothed version (bins of 0.1 period)
     476macro fold.one.period
     477  if ($0 != 5)
     478    echo "USAGE: fold.one.period (time) (mag) (magErr) (period)"
     479    break
     480  end
     481
     482  local myTime myMag myMagErr myPeriod
     483  $myTime = $1
     484  $myMag  = $2
     485  $myMagErr  = $3
     486  $myPeriod = $4
     487
     488  set phi = $myTime / $myPeriod - int($myTime / $myPeriod)
     489
     490  if ($PLOT_FOLD)
     491    lim -n phi phi $myMag; clear; box;
     492  end
     493
     494  delete -q magResid
     495
     496  $dPhi = 0.05; # half of bin size
     497  create nphi $dPhi {1 + $dPhi} {2*$dPhi}
     498  set magR = zero(nphi)
     499  set magS = zero(nphi)
     500  for i 0 nphi[]
     501    subset tmp_mag_sub = $myMag where (phi >= nphi[$i] - $dPhi) && (phi < nphi[$i] + $dPhi)
     502    vstat -q tmp_mag_sub
     503    magR[$i] = $MEDIAN
     504    magS[$i] = $SIGMA
     505
     506    set magDelta = tmp_mag_sub - $MEDIAN
     507    concat magDelta magResid
     508
     509    if ($PLOT_FOLD)
     510      subset tmp_phi_sub = phi where (phi >= nphi[$i] - $dPhi) && (phi < nphi[$i] + $dPhi)
     511      if ($i % 2)
     512        plot tmp_phi_sub tmp_mag_sub -pt 7 -sz 3 -c blue -lw 2
     513      else
     514        plot tmp_phi_sub tmp_mag_sub -pt 7 -sz 3 -c red -lw 2
     515      end
     516    end 
     517  end
     518
     519  if ($PLOT_FOLD) 
     520    plot -pt 10 -sz 1.5 phi $myMag -dy $myMagErr
     521    plot -pt 2 -sz 2.0 -c red nphi magR -dy magS
     522  end
     523
     524  vstat -q magResid
     525end
     526
     527
    281528
    282529# Memory test
     
    298545
    299546 for i 0 100
    300   periodogram_fm t f 2 30 period power
     547  periodogram_fm t f df 2 30 period power
    301548 end
    302549 
  • trunk/Ohana/src/opihi/cmd.data/test/periodogram.sh

    r40165 r40291  
    209209# test using fewer random samples, high frequency, non-zero DC, some noise
    210210macro test8
    211  if ($0 != 2)
    212    echo "USAGE: test8: Ndays")
     211 if ($0 != 4)
     212   echo "USAGE: test8: Period Ndays df"
    213213   break
    214214 end
    215215 
    216216 local Ndays
    217  $Ndays = $1
    218 
    219  $PASS = 1
    220  break -auto off
    221 
    222  local P PI
    223  $PI = 3.14159265359
    224  $P  = 0.8*rnd(0) + 0.2
     217 $P = $1
     218 $Ndays = $2
     219 $dM = $3
     220
     221 $PASS = 1
     222 break -auto off
     223
     224 local PI
     225 $PI = 3.14159265359
    225226 $trueP = $P
    226227
     
    230231
    231232 # t is a time in days, but we always have 4 within 1 hour:
    232  set t0 = int(100 * rnd(x))
    233  set dtx = (3/24) * rnd(x)
    234  set t0 = t0 + dtx
     233 set tday = int(100 * rnd(x)); # choose Ndays random days between 0 and 100
     234 set dtx = (3/24) * rnd(x);  # choose a starting time within that night
     235 set t0 = tday + dtx
    235236
    236237 set dt1 = (15.0 / 1440) * rnd(x) + ( 0 + 7.5) / 1440
     
    244245 set tmp = t0 + dt3; concat tmp t
    245246
    246  set fraw = sin(2*$PI*t/$P) + 0.5
     247 set fraw = 0.75*sin(2*$PI*t/$P)
    247248
    248249 # 0.05 : peakpos = 14.95
    249250 # 0.10 : peakpos = 15.04 (
    250  gaussdev df t[] 0.0 0.25
     251 gaussdev df t[] 0.0 $dM
    251252 set f = fraw + df
    252253
     
    260261 if (abs ($peakpos - $P) > 0.05)
    261262   $PASS = 0
     263 end
     264 if ($PLOT)
     265  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
    262266 end
    263267end
  • trunk/Ohana/src/opihi/cmd.data/uniq.c

    r39457 r40291  
    8080    memcpy (indata, ivec->elements.Int, ivec[0].Nelements*sizeof(opihi_int));
    8181
    82     isort (indata, ivec->Nelements);
     82    llsort (indata, ivec->Nelements);
    8383
    8484    Nnew = 0;
  • trunk/Ohana/src/opihi/cmd.data/write_vectors.c

    r39360 r40291  
    165165        } else {
    166166          if (CSV) {
    167             fprintf (f, "%d,", vec[j][0].elements.Int[i]);
     167            fprintf (f, OPIHI_INT_FMT",", vec[j][0].elements.Int[i]);
    168168          } else {
    169             fprintf (f, "%d ", vec[j][0].elements.Int[i]);
     169            fprintf (f, OPIHI_INT_FMT" ", vec[j][0].elements.Int[i]);
    170170          }
    171171        }
  • trunk/Ohana/src/opihi/dvo/dvo_host_utils.c

    r39524 r40291  
    284284    // XXX a bit of a waste (but only 1024 * 60 bytes or so
    285285    ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH);
    286     snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);
     286    snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.%04d.fits", table->hosts[i].pathname, uniquer, table->hosts[i].hostID);
    287287
    288288    int    Ninvec = 0;
  • trunk/Ohana/src/opihi/dvo/gimages.c

    r39347 r40291  
    214214    if (PixelCoords) {
    215215      gprint (GP_LOG, "%3d %5d %s %6.1f %6.1f %20s %5d %2d %4.2f %6.3f %5.3f %5.3f %4x %7d\n",
    216               Nfound, (int) i, image[i].name, X, Y, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].flags, image[i].imageID);
     216              Nfound, (int) i, image[i].name, X, Y, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].McalPSF, image[i].dMcal, image[i].exptime, image[i].flags, image[i].imageID);
    217217    } else {
    218218      XY_to_RD (&ra, &dec, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    219219      gprint (GP_LOG, "%3d %5d %s %8.4f %8.4f %20s %5d %2d %4.2f %6.3f %5.3f %5.3f %4x %7d\n",
    220               Nfound, (int) i, image[i].name, ra, dec, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].flags, image[i].imageID);
     220              Nfound, (int) i, image[i].name, ra, dec, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].McalPSF, image[i].dMcal, image[i].exptime, image[i].flags, image[i].imageID);
    221221    }
    222222    sprintf (name, "IMAGEx:%d", Nfound);
  • trunk/Ohana/src/opihi/dvo/gstar.c

    r39634 r40291  
    760760
    761761            if (FULL_OUTPUT) {
    762               gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mcal);
     762              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].McalPSF);
     763              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].McalAPER);
    763764              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mflat);
    764               gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Map);
    765               gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].Mkron);
     765              Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt], MAG_CLASS_APER);
     766              gprint (GP_LOG, "%6.3f ", Mrel);
     767              Mrel = PhotRel (&catalog.measure[Nv], &catalog.average[k], &catalog.secfilt[k*Nsecfilt], MAG_CLASS_KRON);
     768              gprint (GP_LOG, "%6.3f ", Mrel);
    766769              gprint (GP_LOG, "%6.3f ", catalog.measure[Nv].dMkron);
    767770              gprint (GP_LOG, "%5.1f ", pow(10.0, 0.4*catalog.measure[Nv].dt));
     
    960963        print_double (NAN);
    961964      } else {
    962         print_double_exp (secfilt[seq].Mstdev);
     965        print_double_exp (secfilt[seq].sMpsfChp);
    963966      }
    964967      break;
     
    10231026        print_double (NAN);
    10241027      } else {
    1025         print_double (secfilt[seq].M);
     1028        print_double (secfilt[seq].MpsfChp);
    10261029      }
    10271030      break;
     
    10311034        print_double (NAN);
    10321035      } else {
    1033         print_double (secfilt[seq].dM);
     1036        print_double (secfilt[seq].dMpsfChp);
    10341037      }
    10351038      break;
     
    10391042        print_double (NAN);
    10401043      } else {
    1041         print_double (secfilt[seq].Map);
     1044        print_double (secfilt[seq].MapChp);
    10421045      }
    10431046      break;
     
    10471050        print_double (NAN);
    10481051      } else {
    1049         print_double (secfilt[seq].dMap);
     1052        print_double (secfilt[seq].dMapChp);
    10501053      }
    10511054      break;
     
    10551058        print_double (NAN);
    10561059      } else {
    1057         print_double_exp (secfilt[seq].sMap);
     1060        print_double_exp (secfilt[seq].sMapChp);
    10581061      }
    10591062      break;
     
    10631066        print_double (NAN);
    10641067      } else {
    1065         print_double_exp (secfilt[seq].dMap);
     1068        print_double_exp (secfilt[seq].dMapChp);
    10661069      }
    10671070      break;
     
    10711074        print_double (NAN);
    10721075      } else {
    1073         print_double (secfilt[seq].Mkron);
     1076        print_double (secfilt[seq].MkronChp);
    10741077      }
    10751078      break;
     
    10791082        print_double (NAN);
    10801083      } else {
    1081         print_double (secfilt[seq].dMkron);
     1084        print_double (secfilt[seq].dMkronChp);
    10821085      }
    10831086      break;
     
    10871090        print_double (NAN);
    10881091      } else {
    1089         print_double_exp (secfilt[seq].sMkron);
     1092        print_double_exp (secfilt[seq].sMkronChp);
    10901093      }
    10911094      break;
     
    10951098        print_double (NAN);
    10961099      } else {
    1097         print_double_exp (secfilt[seq].dMkron);
     1100        print_double_exp (secfilt[seq].dMkronChp);
    10981101      }
    10991102      break;
  • trunk/Ohana/src/opihi/dvo/imdata.c

    r39457 r40291  
    183183        for (i = 0; i < catalog.Nmeasure; i++) {
    184184          if ((catalog.measure[i].t < start) || (catalog.measure[i].t > stop)) continue;
    185           vec[0].elements.Flt[N] = catalog.measure[i].Mcal;
     185          vec[0].elements.Flt[N] = catalog.measure[i].McalPSF;
    186186          N++;
    187187          CHECK_REALLOCATE (vec[0].elements.Flt, opihi_flt, NPTS, N, 1000);
  • trunk/Ohana/src/opihi/dvo/imlist.c

    r39310 r40291  
    141141    if (VERBOSE) {
    142142      gprint (GP_LOG, "%3lld %s %8lld %8.4f %8.4f %f %5d %2d %4.2f %5.3f %5.3f",
    143                          (long long) i, image[i].name, (long long) image[i].imageID, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal);
     143                         (long long) i, image[i].name, (long long) image[i].imageID, r, d, t, image[i].nstar, image[i].photcode, image[i].secz, image[i].McalPSF, image[i].dMcal);
    144144
    145145      if (showUR) {
  • trunk/Ohana/src/opihi/dvo/imphot.c

    r39233 r40291  
    6464      for (x = 0; x < 100; x+=1.0, p++) {
    6565        // *p = applyMcal (&image[subset[0]], (fx*x), (fy*y));
    66         *p = image[subset[0]].Mcal;
     66        *p = image[subset[0]].McalPSF;
    6767      }
    6868    }
     
    7171  for (j = 0; j < Nsubset; j++) {
    7272    i = subset[j];
    73     gprint (GP_ERR, "%s: %f\n", image[i].name, image[i].Mcal);
     73    gprint (GP_ERR, "%s: %f\n", image[i].name, image[i].McalPSF);
    7474
    7575// XXX old code when we had the option of a 2D zero point model
     
    7777    switch (image[i].order) {
    7878    case 0:
    79       gprint (GP_ERR, "%s: %d - %f\n", image[i].name, image[i].order, image[i].Mcal);
     79      gprint (GP_ERR, "%s: %d - %f\n", image[i].name, image[i].order, image[i].McalPSF);
    8080      break;
    8181    case 1:
    82       gprint (GP_ERR, "%s: %d - %f, %d %d\n", image[i].name, image[i].order, image[i].Mcal, image[i].Mx, image[i].My);
     82      gprint (GP_ERR, "%s: %d - %f, %d %d\n", image[i].name, image[i].order, image[i].McalPSF, image[i].Mx, image[i].My);
    8383      break;
    8484    case 2:
    85       gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d\n", image[i].name, image[i].order, image[i].Mcal, image[i].Mx, image[i].My, image[i].Mxx, image[i].Mxy, image[i].Myy);
     85      gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d\n", image[i].name, image[i].order, image[i].McalPSF, image[i].Mx, image[i].My, image[i].Mxx, image[i].Mxy, image[i].Myy);
    8686      break;
    8787    case 3:
    88       gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d, %d %d %d %d\n", image[i].name, image[i].order, image[i].Mcal, image[i].Mx, image[i].My,
     88      gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d, %d %d %d %d\n", image[i].name, image[i].order, image[i].McalPSF, image[i].Mx, image[i].My,
    8989               image[i].Mxx, image[i].Mxy, image[i].Myy, image[i].Mxxx, image[i].Mxxy, image[i].Mxyy, image[i].Myyy);
    9090      break;
    9191    case 4:
    92       gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d, %d %d %d %d, %d %d %d %d %d\n", image[i].name, image[i].order, image[i].Mcal, image[i].Mx, image[i].My,
     92      gprint (GP_ERR, "%s: %d - %f, %d %d, %d %d %d, %d %d %d %d, %d %d %d %d %d\n", image[i].name, image[i].order, image[i].McalPSF, image[i].Mx, image[i].My,
    9393               image[i].Mxx, image[i].Mxy, image[i].Myy, image[i].Mxxx, image[i].Mxxy, image[i].Mxyy, image[i].Myyy,
    9494               image[i].Mxxxx, image[i].Mxxxy, image[i].Mxxyy, image[i].Mxyyy, image[i].Myyyy);
  • trunk/Ohana/src/opihi/dvo/imstats.c

    r40165 r40291  
    4141    Xvec.elements.Flt[i] = image[i].secz;
    4242    if (Mcal)
    43       Yvec.elements.Flt[i] = image[i].Mcal;
     43      Yvec.elements.Flt[i] = image[i].McalPSF;
    4444    else
    4545      Yvec.elements.Flt[i] = image[i].dMcal;
     
    4747    gprint (GP_ERR, "%d %8.4f %8.4f %10d %6d  %5.3f %6.3f %6.3f\n",
    4848             i, r, d, image[i].tzero, image[i].nstar, Xvec.elements.Flt[i],
    49              image[i].Mcal, image[i].dMcal);
     49             image[i].McalPSF, image[i].dMcal);
    5050  }
    5151  if (AutoLimits) SetLimits (&Xvec, &Yvec, &graphmode);
  • trunk/Ohana/src/opihi/dvo/objectcoverage.c

    r39457 r40291  
    203203        if (catalog.secfilt[j*Nsecfilt+Nsec].Ncode < 2) { continue; }
    204204
    205         invalid = ((catalog.secfilt[j*Nsecfilt + Nsec].M < 1.0) || (isnan(catalog.secfilt[j*Nsecfilt + Nsec].M)));
     205        invalid = ((catalog.secfilt[j*Nsecfilt + Nsec].MpsfChp < 1.0) || (isnan(catalog.secfilt[j*Nsecfilt + Nsec].MpsfChp)));
    206206        if (invalid) continue;
    207207       
  • trunk/Ohana/src/opihi/dvo/paverage.c

    r40165 r40291  
    125125      while (average[i].R > Rmax) average[i].R -= 360.0;
    126126
    127       mag = secfilt[i*Nsecfilt+Nsec].M;
     127      mag = secfilt[i*Nsecfilt+Nsec].MpsfChp;
    128128      Zvec[Npts] = MIN (1.0, MAX (0.01, (mag - Mz) / Mr));
    129129      if (LimExclude && (Zvec[Npts] > 0.99)) continue;
  • trunk/Ohana/src/opihi/dvo/remote.c

    r39283 r40291  
    2727    gprint (GP_ERR, "  -skip-result : do not try to read from the result file\n");
    2828    gprint (GP_ERR, "OR:    remote -reload (uniquer)\n");
     29    gprint (GP_ERR, "       (reloads the remote host results into vectors as if a parallel command were run)\n");
    2930    gprint (GP_ERR, "OR:    remote -get-results (uniquer)\n");
     31    gprint (GP_ERR, "       (generates the list of remote result filenames and status variables)\n");
     32    gprint (GP_ERR, "       (RESULT_FILE:i is the filenme, RESULT_STATUS:i is the dvo_client exit status)\n");
    3033    return FALSE;
    3134  }
  • trunk/Ohana/src/opihi/dvo/skycoverage.c

    r39233 r40291  
    330330              break;
    331331            case MIN_MCAL:
    332               V[ys*Nx + xs] = MIN(V[ys*Nx + xs], image[i].Mcal);
     332              V[ys*Nx + xs] = MIN(V[ys*Nx + xs], image[i].McalPSF);
    333333              break;
    334334            case MAX_MCAL:
    335               V[ys*Nx + xs] = MAX(V[ys*Nx + xs], image[i].Mcal);
     335              V[ys*Nx + xs] = MAX(V[ys*Nx + xs], image[i].McalPSF);
    336336              break;
    337337            case MIN_TIME: {
  • trunk/Ohana/src/opihi/include/astro.h

    r39610 r40291  
    4747double VectorFractionInterpolate (double *values, float fraction, int Npts);
    4848
    49 int PlxSetMeanEpoch (double *R, double *D, double *T, double *Rmean, double *Dmean, double *Tmean, int *mask, int Ntotal);
    50 int PlxSetEpochPosition (PlxFitData *fitdata, double *R, double *D, double *dR, double *dD, double *T, int *mask, int Ntotal, Coords *coords, double Tmean);
    51 int PlxOutlierClip (PlxFitData *fitdata, int *mask, int Noutlier, float dPsigMax, Vector *dPvec, int VERBOSE);
     49int PlxSetMeanEpoch (double *R, double *D, double *T, double *Rmean, double *Dmean, double *Tmean, opihi_int *mask, int Ntotal);
     50int PlxSetEpochPosition (PlxFitData *fitdata, double *R, double *D, double *dR, double *dD, double *T, opihi_int *mask, int Ntotal, Coords *coords, double Tmean);
     51int PlxOutlierClip (PlxFitData *fitdata, opihi_int *mask, int Noutlier, float dPsigMax, Vector *dPvec, int VERBOSE);
    5252
    5353int PlxFitDataAlloc (PlxFitData *data, int N);
  • trunk/Ohana/src/opihi/include/data.h

    r37807 r40291  
    162162/* starfuncs.c */
    163163double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE);
     164double get_box_stats (Matrix *matrix, int X, int Y, int dX, int dY, int Nborder, double max, int VERBOSE);
     165
    164166int set_rough_radii (double Ra, double Ri, double Ro);
    165167int get_rough_star (float *data, int Nx, int Ny, int x, int y, opihi_flt *xc, opihi_flt *yc, opihi_flt *sx, opihi_flt *sy, opihi_flt *sxy, opihi_flt *zs, opihi_flt *zp, opihi_flt *sk);
  • trunk/Ohana/src/opihi/lib.data/graphtools.c

    r38153 r40291  
    1010  if (xvec != NULL) {
    1111    if (xvec->type == OPIHI_FLT) {
    12       maxX = DBL_MIN;
     12      maxX = -DBL_MAX;
    1313      minX = DBL_MAX;
    1414      for (i = 0; i < xvec[0].Nelements; i++) {
     
    3333  if (yvec != NULL) {
    3434    if (yvec->type == OPIHI_FLT) {
    35       maxY = DBL_MIN;
     35      maxY = -DBL_MAX;
    3636      minY = DBL_MAX;
    3737      for (i = 0; i < yvec[0].Nelements; i++) {
  • trunk/Ohana/src/opihi/lib.data/starfuncs.c

    r36679 r40291  
    101101}
    102102
     103double get_box_stats (Matrix *matrix, int X, int Y, int dX, int dY, int Nborder, double max, int VERBOSE) {
     104
     105  double *ring;
     106  double x, y, x2, y2, xy, I, sky, FWHMx, FWHMy, value, mag, Sxy;
     107  int i, j, n, Nring, Nmax;
     108  double Npts, gain, dsky2, dmag, peak, offset;
     109  char *string;
     110 
     111  string = get_variable ("GAIN");
     112  if (string == (char *) NULL) {
     113    gprint (GP_ERR, "assuming a value of 1.0\n");
     114    gain = 1.0;
     115  } else {
     116    gain = atof (string);
     117  }
     118  Nborder = MAX (1, Nborder);
     119  Nborder = MIN (1000, Nborder);
     120 
     121  int dX2 = (int)(0.5*dX);
     122  int dY2 = (int)(0.5*dY);
     123  dX = 2 * dX2 + 1;
     124  dY = 2 * dY2 + 1;
     125
     126  Nring = 2*Nborder*(dX + 2*Nborder) + 2*Nborder*(dY + 2*Nborder);
     127  ALLOCATE (ring, double, Nring);
     128  bzero (ring, sizeof(double)*Nring);
     129
     130  // get the pixels in the border regions:
     131  // XXX gfits_get_matrix_value returns 0 for out-of-bounds pixels, but should return NAN
     132  // and they should be skipped
     133  n = 0; 
     134  for (j = 0; j < Nborder; j++) {
     135    for (i = X - dX2 - Nborder; i < X + dX2 + Nborder + 1; i++) {
     136      value = gfits_get_matrix_value (matrix, i, (int)(Y - dY2 - j));
     137      if (isfinite(value)) { ring[n] = value; n++; }
     138      value = gfits_get_matrix_value (matrix, i, (int)(Y + dY2 + j));
     139      if (isfinite(value)) { ring[n] = value; n++; }
     140    }
     141    for (i = Y - dY2; i < Y + dY2 + 1; i++) {
     142      value = gfits_get_matrix_value (matrix, (int)(X - dX2 - j), i);
     143      if (isfinite(value)) { ring[n] = value; n++; }
     144      value = gfits_get_matrix_value (matrix, (int)(X + dX2 + j), i);
     145      if (isfinite(value)) { ring[n] = value; n++; }
     146    }
     147  }
     148  Nring = n;
     149  dsort (ring, Nring);
     150  for (Npts = sky = dsky2 = 0, i = 0.25*Nring; i < 0.75*Nring; i++, Npts += 1.0) {
     151    sky += ring[i];
     152    dsky2 += ring[i]*ring[i];
     153  }
     154  sky = sky / Npts;
     155  dsky2 = dsky2 / Npts - sky*sky;
     156  free (ring);
     157
     158  float dx, dy;
     159
     160  peak = 0;
     161  Npts = Nmax = 0;
     162  x = y = x2 = y2 = xy = I = 0;
     163  for (i = X - dX2; i < X + dX2 + 1; i++) {
     164    for (j = Y - dY2; j < Y + dY2 + 1; j++) {
     165      value = gfits_get_matrix_value (matrix, i, j);
     166      if (!isfinite(value)) continue;
     167      offset = value - sky;
     168      dx = i - X;
     169      dy = j - Y;
     170      x  += dx*offset;
     171      y  += dy*offset;
     172      x2 += dx*dx*offset;
     173      y2 += dy*dy*offset;
     174      xy += dx*dy*offset;
     175      I  += offset;
     176      Npts ++;
     177      if (value > max) {
     178        Nmax ++;
     179      }
     180      if (value > peak) peak = value;
     181    }
     182  }
     183
     184  x = x / I;
     185  y = y / I;
     186  FWHMx = 2.355*sqrt (fabs(x2 / I - x*x));
     187  FWHMy = 2.355*sqrt (fabs(y2 / I - y*y));
     188  Sxy   = xy / I - x*y;
     189  mag = -2.5*log10(I);
     190
     191  // flux_error = sqrt( I + Npts*dsky2 )
     192  // dmag = 1.086 * flux_error / flux
     193  dmag = 1.086 * sqrt (fabs(I + Npts*dsky2)) / (gain * I);
     194  x = x + X;
     195  y = y + Y;
     196 
     197  set_variable ("Xg", x);
     198  set_variable ("Yg", y);
     199  set_variable ("SXg", FWHMx);
     200  set_variable ("SYg", FWHMy);
     201  set_variable ("SXYg", Sxy);
     202  set_variable ("Sg", sky);
     203  set_variable ("dSg", sqrt (fabs (dsky2)));
     204  set_variable ("Zg", mag);
     205  set_variable ("dZg", dmag);
     206  set_variable ("Zcg", I);
     207  set_variable ("Zpk", peak);
     208  set_int_variable ("Nsat", Nmax);
     209  set_int_variable ("Npts", Npts);
     210 
     211  if (VERBOSE) gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
     212
     213  return (mag);
     214
     215}
     216
    103217static double Raper  =  5;
    104218static double Rinner = 10;
  • trunk/Ohana/src/opihi/lib.shell/VectorIO.c

    r39457 r40291  
    4141    for (j = 0; j < Nvec; j++) {
    4242      // if the format is not defined, just use the native byte-widths
    43       tformat[2*j + 0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'J';
     43      tformat[2*j + 0] = (vec[j][0].type == OPIHI_FLT) ? 'D' : 'K'; // this depends on opihi_int == int64_t for Int
    4444      tformat[2*j + 1] = 0;
    4545    }
     
    6060  for (j = 0; j < Nvec; j++) {
    6161    if (vec[j][0].type == OPIHI_FLT) {
    62       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double", vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder);
     62      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "double",  vec[j][0].elements.Flt, vec[j][0].Nelements, nativeOrder);
    6363    } else {
    64       gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
     64//    gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int",     vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
     65      gfits_set_bintable_column_reformat (theader, ftable, vec[j][0].name, "int64_t", vec[j][0].elements.Int, vec[j][0].Nelements, nativeOrder);
    6566    }
    6667  }
     
    328329  ASSIGN_DATA(short,   short,   Int);
    329330  ASSIGN_DATA(int,     int,     Int);
    330   ASSIGN_DATA(int64_t, int64_t, Flt); // int64_t has a problem: Int is too small, Flt is wrong precision
     331  ASSIGN_DATA(int64_t, int64_t, Int); // XXX this works if opihi_int is assigned to int64_t
     332//ASSIGN_DATA(int64_t, int64_t, Flt); // int64_t has a problem: Int is too small, Flt is wrong precision
    331333  ASSIGN_DATA(float,   float,   Flt);
    332334  ASSIGN_DATA(double,  double,  Flt);
     
    353355  ASSIGN_DATA_TRANSPOSE(short,   short,   Int);
    354356  ASSIGN_DATA_TRANSPOSE(int,     int,     Int);
    355   ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Flt);
     357  ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Int);
     358//ASSIGN_DATA_TRANSPOSE(int64_t, int64_t, Flt); // see above comment
    356359  ASSIGN_DATA_TRANSPOSE(float,   float,   Flt);
    357360  ASSIGN_DATA_TRANSPOSE(double,  double,  Flt);
  • trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r39558 r40291  
    120120        Nop_stack ++;
    121121        break;
    122       case ST_UNARY:
    123122      case ST_BINARY:
    124123      case ST_TRINARY:
     
    139138        Nop_stack ++;
    140139        break;
     140      case ST_UNARY:
    141141      case ST_LEFT: 
    142142        /* push operator on OP stack */
  • trunk/Ohana/src/opihi/lib.shell/dvomath.c

    r39457 r40291  
    2929  unsigned int Ncstack;
    3030  cstack = isolate_elements (argc, argv, &Ncstack);
     31
     32  // for (i = 0; i < Ncstack; i++) {
     33  //   fprintf (stderr, "%d : %s\n", i, cstack[i]);
     34  // }
    3135
    3236  /* generate RPN stack from cstack arguments */
     
    8286      } else {
    8387        if (stack[0].type == ST_SCALAR_INT) {
    84           sprintf (outname, "%d", stack[0].IntValue);
     88          sprintf (outname, OPIHI_INT_FMT, stack[0].IntValue);
    8589        } else {
    8690          sprintf (outname, "%.12g", stack[0].FltValue);
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r40014 r40291  
    8989      }
    9090      if (tmp_stack.type == ST_SCALAR_INT) {
    91         gprint (GP_ERR, "---> %d ", tmp_stack.IntValue);
     91        gprint (GP_ERR, "---> "OPIHI_INT_FMT" ", tmp_stack.IntValue);
    9292      }
    9393      if (tmp_stack.type == ST_SCALAR_FLT) {
     
    110110
    111111        if (i < 3) {  /* need two variables to operate on */
    112           snprintf (line, 512, "syntax error: trinary operator without three operands: %s\n", stack[i].name);
     112          snprintf (line, 512, "syntax error: trinary operator without three operands: %s\n(Note that the : in a trinary operation must be protected by spaces", stack[i].name);
    113113          push_error (line);
    114114          clear_stack (&tmp_stack);
     
    124124
    125125        /* there are no valid unary string operators */
    126         snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)", stack[i].name);
     126        snprintf (line, 512, "invalid operands for trinary operator %s (mismatch types?)\n(Note that the : in a trinary operation must be protected by spaces)", stack[i].name);
    127127        push_error (line);
    128128        clear_stack (&tmp_stack);
     
    131131      got_three_op:
    132132        if (!status) {
    133           snprintf (line, 512, "syntax error: invalid operand for trinary operation: %s or %s or %s\n", stack[i-1].name, stack[i-2].name, stack[i-3].name);
     133          snprintf (line, 512, "syntax error: invalid operand for trinary operation: %s or %s or %s\n(Note that the : in a trinary operation must be protected by spaces)", stack[i-1].name, stack[i-2].name, stack[i-3].name);
    134134          push_error (line);
    135135          clear_stack (&tmp_stack);
     
    188188          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
    189189          push_error (line);
     190          if (strchr(stack[i-1].name, ':') || strchr(stack[i-2].name, ':')) {
     191            snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n(Note that the : in a trinary operation must be protected by spaces)\n", stack[i-1].name, stack[i-2].name);
     192            push_error (line);
     193          }
    190194          clear_stack (&tmp_stack);
    191195          return (FALSE);
  • trunk/Ohana/src/opihi/lib.shell/parse.c

    r33662 r40291  
    245245        vec[0].elements.Flt[Nx] = atof (val);
    246246      } else {
    247         vec[0].elements.Int[Nx] = atol (val);
     247        vec[0].elements.Int[Nx] = atoll (val);
    248248      }
    249249    }
  • trunk/Ohana/src/photdbc/src/get_mags.c

    r37045 r40291  
    2020    Nlist = MAX (Nlist, catalog[0].average[i].Nm);
    2121    for (j = 0; j < Nsecfilt; j++) {
    22       catalog[0].secfilt[i*Nsecfilt+j].M  = NAN;
    23       catalog[0].secfilt[i*Nsecfilt+j].dM = NAN;
    24       catalog[0].secfilt[i*Nsecfilt+j].Mchisq = NAN;
     22      catalog[0].secfilt[i*Nsecfilt+j].MpsfChp  = NAN;
     23      catalog[0].secfilt[i*Nsecfilt+j].dMpsfChp = NAN;
     24      catalog[0].secfilt[i*Nsecfilt+j].Mchisq   = NAN;
    2525    }
    2626  }
     
    5252      if (N < 1) continue;
    5353   
    54       Mval = (Nsec == -1) ? &catalog[0].average[i].M : &catalog[0].secfilt[i*Nsecfilt+Nsec].M;
     54      Mval = (Nsec == -1) ? &catalog[0].average[i].M : &catalog[0].secfilt[i*Nsecfilt+Nsec].MpsfChp;
    5555      *Mval = stats.mean;
    56       Mval = (Nsec == -1) ? &catalog[0].average[i].dM : &catalog[0].secfilt[i*Nsecfilt+Nsec].dM;
     56      Mval = (Nsec == -1) ? &catalog[0].average[i].dM : &catalog[0].secfilt[i*Nsecfilt+Nsec].dMpsfChp;
    5757      *Mval = stats.sigma;
    5858      Mval = (Nsec == -1) ? &catalog[0].average[i].Mchisq : &catalog[0].secfilt[i*Nsecfilt+Nsec].Mchisq;
  • trunk/Ohana/src/photdbc/src/join_stars.c

    r38441 r40291  
    8787
    8888    // require base star to meet certain conditions:
    89     if (isnan(secfilt[Ni*Nsecfilt + baseNsec].M)) {
     89    if (isnan(secfilt[Ni*Nsecfilt + baseNsec].MpsfChp)) {
    9090      i++;
    9191      continue;
  • trunk/Ohana/src/photdbc/src/make_subcatalog.c

    r39926 r40291  
    11# include "photdbc.h"
     2
     3# define SKIP_MEASURE FALSE
     4# define SKIP_LENSING FALSE
     5# define SKIP_LENSOBJ FALSE
     6# define SKIP_STARPAR FALSE
     7# define SKIP_GALPHOT FALSE
    28
    39// copy a catalog to a new subcatalog, applying some filters
     
    6369      keep = FALSE;
    6470      for (j = 0; !keep && (j < Nsecfilt); j++) {
    65         if (catalog[0].secfilt[Nsecfilt*i+j].dM < AVE_SIGMA_LIM) {
     71        if (catalog[0].secfilt[Nsecfilt*i+j].dMpsfChp < AVE_SIGMA_LIM) {
    6672          keep = TRUE;
    6773        }
     
    98104    minSigma = 32;
    99105    Nm = 0;
    100     for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
     106    for (j = 0; !SKIP_MEASURE && (j < catalog[0].average[i].Nmeasure); j++) {
    101107
    102108      offset = catalog[0].average[i].measureOffset + j;
     
    164170      }
    165171    }
     172    // End of average[i] loop
    166173
    167174    // exclude faint objects
     
    189196    Nm = 0;
    190197    subcatalog[0].average[Naverage].lensingOffset = Nlensing;
    191     for (j = 0; j < catalog[0].average[i].Nlensing; j++) {
     198    for (j = 0; !SKIP_LENSING && (j < catalog[0].average[i].Nlensing); j++) {
    192199
    193200      offset = catalog[0].average[i].lensingOffset + j;
     
    208215    Nm = 0;
    209216    subcatalog[0].average[Naverage].lensobjOffset = Nlensobj;
    210     for (j = 0; j < catalog[0].average[i].Nlensobj; j++) {
     217    for (j = 0; !SKIP_LENSOBJ && (j < catalog[0].average[i].Nlensobj); j++) {
    211218
    212219      offset = catalog[0].average[i].lensobjOffset + j;
     
    226233    Nm = 0;
    227234    subcatalog[0].average[Naverage].starparOffset = Nstarpar;
    228     for (j = 0; j < catalog[0].average[i].Nstarpar; j++) {
     235    for (j = 0; !SKIP_STARPAR && (j < catalog[0].average[i].Nstarpar); j++) {
    229236
    230237      offset = catalog[0].average[i].starparOffset + j;
     
    245252    Nm = 0;
    246253    subcatalog[0].average[Naverage].galphotOffset = Ngalphot;
    247     for (j = 0; j < catalog[0].average[i].Ngalphot; j++) {
     254    for (j = 0; !SKIP_GALPHOT && (j < catalog[0].average[i].Ngalphot); j++) {
    248255
    249256      offset = catalog[0].average[i].galphotOffset + j;
  • trunk/Ohana/src/relastro/include/relastro.h

    r39926 r40291  
    215215  unsigned int stop;
    216216  off_t myImage;
    217   float Mcal;
     217  float McalPSF;
     218  float McalAPER;
    218219  float dMcal;
    219   short Xm;
     220  float McalChiSq;
    220221  float secz;
    221222  char flags;
     
    377378int    SKIP_CFH;
    378379
     380int    UPDATE_ALL_MEASURE;
    379381int    UPDATE_PS1_STACK_MEASURE;
    380382int    UPDATE_PS1_CHIP_MEASURE;
  • trunk/Ohana/src/relastro/src

  • trunk/Ohana/src/relastro/src/BrightCatalog.c

    r39995 r40291  
    6868    GET_COLUMN(D,         "DEC",        double);
    6969    GET_COLUMN(M,         "MAG_SYS",    float);
    70     GET_COLUMN(Mcal,      "MAG_CAL",    float);
     70    GET_COLUMN(McalPSF,   "MCAL_PSF",   float);
     71    GET_COLUMN(McalAPER,  "MCAL_APER",  float);
    7172    GET_COLUMN(dM,        "MAG_ERR",    float);
    7273    GET_COLUMN(airmass,   "AIRMASS",    float);
     
    9495      measure[i].D         = D[i];
    9596      measure[i].M         = M[i];
    96       measure[i].Mcal      = Mcal[i];
     97      measure[i].McalPSF   = McalPSF[i];
     98      measure[i].McalAPER  = McalAPER[i];
    9799      measure[i].dM        = dM[i];
    98100      measure[i].airmass   = airmass[i];
     
    120122    free (D       );
    121123    free (M       );
    122     free (Mcal    );
     124    free (McalPSF );
     125    free (McalAPER);
    123126    free (dM      );
    124127    free (airmass );
     
    285288    ALLOCATE (secfilt, SecFilt, Nrow);
    286289    for (i = 0; i < Nrow; i++) {
    287       secfilt[i].M      = M[i];         
    288       secfilt[i].dM    = dM[i];
    289       secfilt[i].Mchisq = Mchisq[i];
    290       secfilt[i].flags  = flags[i];
    291       secfilt[i].Ncode  = Ncode[i];
    292       secfilt[i].Nused  = Nused[i];
    293       secfilt[i].Mmin   = Mmin[i];
    294       secfilt[i].Mmax   = Mmax[i];
     290      secfilt[i].MpsfChp  = M[i];         
     291      secfilt[i].dMpsfChp = dM[i];
     292      secfilt[i].Mchisq   = Mchisq[i];
     293      secfilt[i].flags    = flags[i];
     294      secfilt[i].Ncode    = Ncode[i];
     295      secfilt[i].Nused    = Nused[i];
     296      secfilt[i].Mmin     = Mmin[i];
     297      secfilt[i].Mmax     = Mmax[i];
    295298    }
    296299    // fprintf (stderr, "loaded data for %lld secfilt\n", (long long) Nrow);
     
    385388    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
    386389    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
    387     float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
     390    float  *McalPSF   ; ALLOCATE (McalPSF  ,  float,  catalog->Nmeasure);
     391    float  *McalAPER  ; ALLOCATE (McalAPER ,  float,  catalog->Nmeasure);
    388392    float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
    389393    float  *airmass   ; ALLOCATE (airmass  ,  float,  catalog->Nmeasure);
     
    408412      D[i]        = measure[i].D        ;
    409413      M[i]        = measure[i].M        ;
    410       Mcal[i]     = measure[i].Mcal     ;
     414      McalPSF[i]  = measure[i].McalPSF  ;
     415      McalAPER[i] = measure[i].McalAPER ;
    411416      dM[i]       = measure[i].dM       ;
    412417      airmass[i]  = measure[i].airmass  ;
     
    434439    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    435440    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    436     gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     441    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",   McalPSF,   catalog->Nmeasure);
     442    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER,  catalog->Nmeasure);
    437443    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",    dM,        catalog->Nmeasure);
    438444    gfits_set_bintable_column (&theader, &ftable, "AIRMASS",    airmass,   catalog->Nmeasure);
     
    454460    free (D       );
    455461    free (M       );
    456     free (Mcal    );
     462    free (McalPSF );
     463    free (McalAPER);
    457464    free (dM      );
    458465    free (airmass );
     
    694701    SecFilt *secfilt = catalog->secfilt;
    695702    for (i = 0; i < Nsec; i++) {
    696       M     [i]       = secfilt[i].M      ;
    697       dM    [i]       = secfilt[i].dM     ;
    698       Mchisq[i]       = secfilt[i].Mchisq ;
    699       flags [i]       = secfilt[i].flags  ;
    700       Ncode [i]       = secfilt[i].Ncode  ;
    701       Nused [i]       = secfilt[i].Nused  ;
    702       Mmin  [i]       = secfilt[i].Mmin   ;
    703       Mmax  [i]       = secfilt[i].Mmax   ;
     703      M     [i]       = secfilt[i].MpsfChp ;
     704      dM    [i]       = secfilt[i].dMpsfChp;
     705      Mchisq[i]       = secfilt[i].Mchisq  ;
     706      flags [i]       = secfilt[i].flags   ;
     707      Ncode [i]       = secfilt[i].Ncode   ;
     708      Nused [i]       = secfilt[i].Nused   ;
     709      Mmin  [i]       = secfilt[i].Mmin    ;
     710      Mmax  [i]       = secfilt[i].Mmax    ;
    704711    }
    705712
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r39926 r40291  
    431431  /**** dMcal vs airmass ****/
    432432  for (i = 0; i < Nimage; i++) {
    433     Mlist[i] = image[i].Mcal;
     433    Mlist[i] = image[i].McalPSF;
    434434    dlist[i] = image[i].dMcal;
    435435    xlist[i] = image[i].secz;
     
    819819
    820820    if ((DCR_BLUE_NSEC_POS >= 0) && (DCR_BLUE_NSEC_NEG >= -1)) {
    821       ref[i].ColorBlue = catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_NEG].M;
     821      ref[i].ColorBlue = catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_POS].MpsfChp - catalog[c].secfilt[n*Nsecfilt + DCR_BLUE_NSEC_NEG].MpsfChp;
    822822    }
    823823    if ((DCR_RED_NSEC_POS >= 0) && (DCR_RED_NSEC_NEG >= -1)) {
    824       ref[i].ColorRed = catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_POS].M - catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_NEG].M;
     824      ref[i].ColorRed = catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_POS].MpsfChp - catalog[c].secfilt[n*Nsecfilt + DCR_RED_NSEC_NEG].MpsfChp;
    825825    }
    826826
  • trunk/Ohana/src/relastro/src/MosaicOps.c

    r39457 r40291  
    9797
    9898    /* a new mosaic, define ranges */
    99     mosaic[Nmosaic].start   = start;
    100     mosaic[Nmosaic].stop    = stop;
    101     mosaic[Nmosaic].Mcal    = 0.0;
    102     mosaic[Nmosaic].dMcal   = 0.0;
    103     mosaic[Nmosaic].Xm      = 0.0;
    104     mosaic[Nmosaic].flags   = image[i].flags;
    105     mosaic[Nmosaic].secz    = image[i].secz;
    106     mosaic[Nmosaic].coords  = image[i].coords;
    107     mosaic[Nmosaic].myImage = i;
     99    mosaic[Nmosaic].start     = start;
     100    mosaic[Nmosaic].stop      = stop;
     101    mosaic[Nmosaic].McalPSF   = 0.0;
     102    mosaic[Nmosaic].McalAPER  = 0.0;
     103    mosaic[Nmosaic].dMcal     = 0.0;
     104    mosaic[Nmosaic].McalChiSq = 0.0;
     105    mosaic[Nmosaic].flags     = image[i].flags;
     106    mosaic[Nmosaic].secz      = image[i].secz;
     107    mosaic[Nmosaic].coords    = image[i].coords;
     108    mosaic[Nmosaic].myImage   = i;
    108109
    109110    // init the mosaic_own_images array data
  • trunk/Ohana/src/relastro/src/UpdateMeasures.c

    r39926 r40291  
    114114      }
    115115
     116      // XXX this stuff is rather hackish, added to do GSC/HSC/Megacam astrometry
     117
     118      // only modify the chip coordinates
     119      if (UPDATE_ALL_MEASURE) {
     120        measureT->R = R;
     121        measureT->D = D;
     122        if (measureB) {
     123          measureB->R = R;
     124          measureB->D = D;
     125        }
     126        goto set_measure_done;
     127      }
    116128      // only modify the chip coordinates
    117129      if (UPDATE_PS1_STACK_MEASURE && isGPC1stack (measureT->photcode)) {
     
    122134          measureB->D = D;
    123135        }
     136        goto set_measure_done;
    124137      }
    125138      // only modify the chip coordinates
     
    131144          measureB->D = D;
    132145        }
    133       }
    134       // only modify the chip coordinates
    135       if (UPDATE_HSC_MEASURE && isGPC1chip (measureT->photcode)) {
    136         measureT->R = R;
    137         measureT->D = D;
    138         if (measureB) {
    139           measureB->R = R;
    140           measureB->D = D;
    141         }
    142       }
    143       // only modify the chip coordinates
    144       if (UPDATE_CFH_MEASURE && isGPC1chip (measureT->photcode)) {
    145         measureT->R = R;
    146         measureT->D = D;
    147         if (measureB) {
    148           measureB->R = R;
    149           measureB->D = D;
    150         }
    151       }
     146        goto set_measure_done;
     147      }
     148      // only modify the chip coordinates
     149      if (UPDATE_HSC_MEASURE && isHSCchip (measureT->photcode)) {
     150        measureT->R = R;
     151        measureT->D = D;
     152        if (measureB) {
     153          measureB->R = R;
     154          measureB->D = D;
     155        }
     156        goto set_measure_done;
     157      }
     158      // only modify the chip coordinates
     159      if (UPDATE_CFH_MEASURE && isCFHchip (measureT->photcode)) {
     160        measureT->R = R;
     161        measureT->D = D;
     162        if (measureB) {
     163          measureB->R = R;
     164          measureB->D = D;
     165        }
     166        goto set_measure_done;
     167      }
     168    set_measure_done:
     169      continue; // XXX this line is needed only to support the label above
    152170    }
    153171    if (VERBOSE) fprintf (stderr, "%s : Noff ori RA %d ( %d %d %d ), Noff ori DEC %d ( %d %d %d )\n", catalog[i].filename, NoffRAori, NoffRAchip, NoffRAstack, NoffRAwarp, NoffDECori, NoffDECchip, NoffDECstack, NoffDECwarp);
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r39926 r40291  
    208208    if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
    209209
     210    if (UPDATE_ALL_MEASURE)       strextend (&command, "-update-all-cameras");
    210211    if (UPDATE_PS1_STACK_MEASURE) strextend (&command, "-update-ps1-stack");
    211     if (UPDATE_PS1_CHIP_MEASURE) strextend (&command, "-update-ps1-chip");
    212     if (UPDATE_HSC_MEASURE)      strextend (&command, "-update-hsc");
    213     if (UPDATE_CFH_MEASURE)      strextend (&command, "-update-cfh");
    214 
    215     if (UPDATE)        strextend (&command, "-update");
     212    if (UPDATE_PS1_CHIP_MEASURE)  strextend (&command, "-update-ps1-chip");
     213    if (UPDATE_HSC_MEASURE)       strextend (&command, "-update-hsc");
     214    if (UPDATE_CFH_MEASURE)       strextend (&command, "-update-cfh");
     215
     216    if (UPDATE)           strextend (&command, "-update");
    216217    if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
    217     if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
    218     if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
     218    if (USE_BASIC_CHECK)  strextend (&command, "-basic-image-search");
     219    if (USE_ALL_IMAGES)   strextend (&command, "-use-all-images");
    219220
    220221    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
     
    347348    if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
    348349
     350    if (UPDATE_ALL_MEASURE)       strextend (&command, "-update-all-cameras");
    349351    if (UPDATE_PS1_STACK_MEASURE) strextend (&command, "-update-ps1-stack");
    350     if (UPDATE_PS1_CHIP_MEASURE) strextend (&command, "-update-ps1-chip");
    351     if (UPDATE_HSC_MEASURE)      strextend (&command, "-update-hsc");
    352     if (UPDATE_CFH_MEASURE)      strextend (&command, "-update-cfh");
     352    if (UPDATE_PS1_CHIP_MEASURE)  strextend (&command, "-update-ps1-chip");
     353    if (UPDATE_HSC_MEASURE)       strextend (&command, "-update-hsc");
     354    if (UPDATE_CFH_MEASURE)       strextend (&command, "-update-cfh");
    353355
    354356    if (UPDATE)        strextend (&command, "-update");
  • trunk/Ohana/src/relastro/src/args.c

    r39926 r40291  
    158158  }
    159159
     160  UPDATE_ALL_MEASURE = FALSE;
     161  if ((N = get_argument (argc, argv, "-update-all-cameras"))) {
     162    remove_argument (N, &argc, argv);
     163    UPDATE_ALL_MEASURE = TRUE;
     164  }
    160165  UPDATE_PS1_STACK_MEASURE = FALSE;
    161166  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     
    179184  }
    180185  if (RELASTRO_OP == OP_UPDATE_OFFSETS) {
    181     if (!UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
    182       fprintf (stderr, "for -update-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
     186    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     187      fprintf (stderr, "for -update-offsets, need to select at least one of -update-all-cameras, -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
    183188      exit (2);
    184189    }
    185190  }
    186191  if ((RELASTRO_OP == OP_PARALLEL_IMAGES) || (RELASTRO_OP == OP_IMAGES)) {
    187     if (APPLY_OFFSETS && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     192    if (APPLY_OFFSETS && !UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
    188193      fprintf (stderr, "for [-images or -parallel-images] with -apply-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
    189194      exit (2);
     
    890895  }
    891896
     897  UPDATE_ALL_MEASURE = FALSE;
     898  if ((N = get_argument (argc, argv, "-update-all-cameras"))) {
     899    remove_argument (N, &argc, argv);
     900    UPDATE_ALL_MEASURE = TRUE;
     901  }
    892902  UPDATE_PS1_STACK_MEASURE = FALSE;
    893903  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     
    911921  }
    912922  if (RELASTRO_OP == OP_UPDATE_OFFSETS) {
    913     if (!UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     923    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
    914924      fprintf (stderr, "for -update-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
    915925      exit (2);
  • trunk/Ohana/src/relphot/include/relphot.h

    r39926 r40291  
    7777  unsigned int stop;
    7878  short photcode;
    79   float Mcal;
     79  float McalPSF;
     80  float McalAPER;
    8081  float dMcal;
    8182  float dMsys;
    82   unsigned short nFitPhotom;
    83   short Xm;
     83  float McalChiSq;
    8484  float secz;
    8585  float ubercalDist;
     86  unsigned short nFitPhotom;
    8687  unsigned int flags;
    8788  char skipCal;               // if TRUE, this mosaic is incomplete and should not be calibrated
     
    201202
    202203typedef struct {
    203   float Mcal;
     204  float McalPSF;
     205  float McalAPER;
    204206  float dMcal;
    205207  float dMagSys;
    206   short Xm;
     208  float McalChiSq;
    207209  int nFitPhotom;
    208210  int flags;
     
    220222
    221223typedef struct {
    222   float Mcal;
     224  float McalPSF;
     225  float McalAPER;
    223226  float dMcal;
    224227  unsigned int imageID;
     
    336339int    SyntheticPhotometry;
    337340
     341int    USE_MCAL_PSF_FOR_STACK_APER;
     342
    338343char  *PhotcodeList;
    339344
     
    404409int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
    405410
     411void clearImages (void);
     412void checkImages (char *name);
     413int dumpMags (FILE *fout, Catalog *catalog, int Ncatalog);
     414
    406415void makeMosaics (Image *image, off_t Nimage, int mergeMcal);
    407416Mosaic *getMosaicForImage (off_t im);
     
    422431off_t         getImageEntry       PROTO((off_t meas, int cat));
    423432
    424 float         getMcal_alt         PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, float Xccd, float Yccd));
    425 float         getMcal             PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog));
     433float         getMcal             PROTO((off_t meas, int cat, dvoMagClassType class));
    426434float         getMflat            PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog));
    427435float         getMgrid            PROTO((off_t meas, int cat));
    428436float         getMmos             PROTO((off_t meas, int cat));
    429 float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat));
     437float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source));
    430438short         getUbercalDist      PROTO((off_t meas, int cat));
    431439float         getCenterOffset     PROTO((off_t meas, int cat, Measure *measure, unsigned int *myID));
  • trunk/Ohana/src/relphot/src/BrightCatalog.c

    r39478 r40291  
    6666    GET_COLUMN(D,         "DEC",        double);
    6767    GET_COLUMN(M,         "MAG_SYS",    float);
    68     GET_COLUMN(Mcal,      "MAG_CAL",    float);
     68    GET_COLUMN(Mkron,     "MAG_KRON",   float);
     69    GET_COLUMN(McalPSF,   "MCAL_PSF",   float);
     70    GET_COLUMN(McalAPER,  "MCAL_APER",  float);
    6971    GET_COLUMN(Mflat,     "MAG_FLAT",   float);
    7072    GET_COLUMN(dM,        "MAG_ERR",    float);
     
    8991      measure[i].D         = D[i];
    9092      measure[i].M         = M[i];
    91       measure[i].Mcal      = Mcal[i];
     93      measure[i].Mkron     = Mkron[i];
     94      measure[i].McalPSF   = McalPSF[i];
     95      measure[i].McalAPER  = McalAPER[i];
    9296      measure[i].Mflat     = Mflat[i];
    9397      measure[i].dM        = dM[i];
     
    110114    free (D       );
    111115    free (M       );
    112     free (Mcal    );
     116    free (Mkron   );
     117    free (McalPSF );
     118    free (McalAPER);
    113119    free (Mflat   );
    114120    free (dM      );
     
    186192    // need to create and assign to flat-field correction
    187193    GET_COLUMN(M,      "MAG",      float);
     194    GET_COLUMN(Mkron,  "MAG_KRON", float);
    188195    GET_COLUMN(dM,     "MAG_ERR",  float);
    189196    GET_COLUMN(Mchisq, "MAG_CHI",  float);
     
    199206    ALLOCATE (secfilt, SecFilt, Nrow);
    200207    for (i = 0; i < Nrow; i++) {
    201       secfilt[i].M      = M[i];         
    202       secfilt[i].dM     = dM[i];
    203       secfilt[i].Mchisq = Mchisq[i];
    204       secfilt[i].flags  = flags[i];
    205       secfilt[i].Ncode  = Ncode[i];
    206       secfilt[i].Nused  = Nused[i];
    207       secfilt[i].Mmin   = Mmin[i];
    208       secfilt[i].Mmax   = Mmax[i];
     208      secfilt[i].MpsfChp  = M[i];         
     209      secfilt[i].MkronChp = Mkron[i];         
     210      secfilt[i].dMpsfChp = dM[i];
     211      secfilt[i].Mchisq   = Mchisq[i];
     212      secfilt[i].flags    = flags[i];
     213      secfilt[i].Ncode    = Ncode[i];
     214      secfilt[i].Nused    = Nused[i];
     215      secfilt[i].Mmin     = Mmin[i];
     216      secfilt[i].Mmax     = Mmax[i];
    209217    }
    210218    fprintf (stderr, "loaded data for %lld secfilt\n", (long long) Nrow);
    211219
    212220    free (M     );
     221    free (Mkron );
    213222    free (dM    );
    214223    free (Mchisq);
     
    271280    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degree", 1.0, 0.0);
    272281    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    273     gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     282    gfits_define_bintable_column (&theader, "E", "MAG_KRON", "magnitude (sys,kron)",        NULL,    1.0, 0.0);
     283    gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "magnitude (cal)",             NULL,    1.0, 0.0);
     284    gfits_define_bintable_column (&theader, "E", "MCAL_APER","magnitude (cal)",             NULL,    1.0, 0.0);
    274285    gfits_define_bintable_column (&theader, "E", "MAG_FLAT", "magnitude (flat)",            NULL,    1.0, 0.0);
    275286    gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "magnitude (err)",             NULL,    1.0, 0.0);
     
    293304    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
    294305    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
    295     float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
     306    float  *Mkron     ; ALLOCATE (Mkron    ,  float,  catalog->Nmeasure);
     307    float  *McalPSF   ; ALLOCATE (McalPSF  ,  float,  catalog->Nmeasure);
     308    float  *McalAPER  ; ALLOCATE (McalAPER ,  float,  catalog->Nmeasure);
    296309    float  *Mflat     ; ALLOCATE (Mflat    ,  float,  catalog->Nmeasure);
    297310    float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
     
    311324    MeasureTiny *measure = catalog->measure;
    312325    for (i = 0; i < catalog->Nmeasure; i++) {
    313       R[i]        = measure[i].R       ;
    314       D[i]        = measure[i].D       ;
     326      R[i]        = measure[i].R        ;
     327      D[i]        = measure[i].D        ;
    315328      M[i]        = measure[i].M        ;
    316       Mcal[i]     = measure[i].Mcal     ;
     329      Mkron[i]    = measure[i].Mkron    ;
     330      McalPSF[i]  = measure[i].McalPSF  ;
     331      McalAPER[i] = measure[i].McalAPER ;
    317332      Mflat[i]    = measure[i].Mflat    ;
    318333      dM[i]       = measure[i].dM       ;
     
    334349    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    335350    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    336     gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     351    gfits_set_bintable_column (&theader, &ftable, "MAG_KRON",   Mkron,     catalog->Nmeasure);
     352    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",   McalPSF,   catalog->Nmeasure);
     353    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER,  catalog->Nmeasure);
    337354    gfits_set_bintable_column (&theader, &ftable, "MAG_FLAT",   Mflat,     catalog->Nmeasure);
    338355    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",    dM,        catalog->Nmeasure);
     
    352369    free (D       );
    353370    free (M       );
    354     free (Mcal    );
     371    free (Mkron   );
     372    free (McalPSF );
     373    free (McalAPER);
    355374    free (Mflat   );
    356375    free (dM      );
     
    436455    gfits_create_table_header (&theader, "BINTABLE", "SECFILT");
    437456
    438     gfits_define_bintable_column (&theader, "E", "MAG",      "",              "arcsec", 1.0, 0.0);
    439     gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "",              "arcsec", 1.0, 0.0);
     457    gfits_define_bintable_column (&theader, "E", "MAG",      "",              "mag",   1.0, 0.0);
     458    gfits_define_bintable_column (&theader, "E", "MAG_KRON", "",              "mag",   1.0, 0.0);
     459    gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "",              "mag",   1.0, 0.0);
    440460    gfits_define_bintable_column (&theader, "E", "MAG_CHI",  "",              NULL,    1.0, 0.0);
    441461    gfits_define_bintable_column (&theader, "J", "FLAGS",    "",              NULL,    1.0, 0.0);
     
    454474    // create intermediate storage arrays
    455475    float *M        ; ALLOCATE (M      ,  float, Nsec);
     476    float *Mkron    ; ALLOCATE (Mkron  ,  float, Nsec);
    456477    float *dM       ; ALLOCATE (dM     ,  float, Nsec);
    457478    float *Mchisq   ; ALLOCATE (Mchisq ,  float, Nsec);
     
    465486    SecFilt *secfilt = catalog->secfilt;
    466487    for (i = 0; i < Nsec; i++) {
    467       M     [i]       = secfilt[i].M      ;
    468       dM    [i]       = secfilt[i].dM     ;
    469       Mchisq[i]       = secfilt[i].Mchisq ;
    470       flags [i]       = secfilt[i].flags  ;
    471       Ncode [i]       = secfilt[i].Ncode  ;
    472       Nused [i]       = secfilt[i].Nused  ;
    473       Mmin  [i]       = secfilt[i].Mmin   ;
    474       Mmax  [i]       = secfilt[i].Mmax   ;
     488      M     [i]       = secfilt[i].MpsfChp ;
     489      Mkron [i]       = secfilt[i].MkronChp;
     490      dM    [i]       = secfilt[i].dMpsfChp;
     491      Mchisq[i]       = secfilt[i].Mchisq  ;
     492      flags [i]       = secfilt[i].flags   ;
     493      Ncode [i]       = secfilt[i].Ncode   ;
     494      Nused [i]       = secfilt[i].Nused   ;
     495      Mmin  [i]       = secfilt[i].Mmin    ;
     496      Mmax  [i]       = secfilt[i].Mmax    ;
    475497    }
    476498
    477499    // add the columns to the output array
    478500    gfits_set_bintable_column (&theader, &ftable, "MAG",      M     , Nsec);
     501    gfits_set_bintable_column (&theader, &ftable, "MAG_KRON", Mkron , Nsec);
    479502    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",  dM    , Nsec);
    480503    gfits_set_bintable_column (&theader, &ftable, "MAG_CHI",  Mchisq, Nsec);
     
    486509
    487510    free (M      );
     511    free (Mkron  );
    488512    free (dM     );
    489513    free (Mchisq );
  • trunk/Ohana/src/relphot/src/GridOps.c

    r39632 r40291  
    401401
    402402        // skip images marked as BAD
    403         Mcal = getMcal  (m, c, flatcorr, catalog);
     403        Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    404404        if (isnan(Mcal)) {
    405405          Ncal ++;
     
    558558        continue;
    559559      }
    560       Mcal = getMcal  (m, c, flatcorr, catalog);
     560      Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    561561      if (isnan(Mcal)) {
    562562        Ncal ++;
     
    568568        continue;
    569569      }
    570       Mrel  = getMrel  (catalog, m, c);
     570      Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    571571      if (isnan(Mrel)) {
    572572        Nrel ++;
     
    645645        continue;
    646646      }
    647       Mcal  = getMcal  (m, c, flatcorr, catalog);
     647      Mcal  = getMcal  (m, c, MAG_CLASS_PSF);
    648648      if (isnan(Mcal)) continue;
    649649      Mmos  = getMmos  (m, c);
    650650      if (isnan(Mmos)) continue;
    651       Mrel  = getMrel  (catalog, m, c);
     651      Mrel  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    652652      if (isnan(Mrel)) continue;
    653653
  • trunk/Ohana/src/relphot/src/ImageMagIO.c

    r37037 r40291  
    5858  char type[16];
    5959
    60   GET_COLUMN (Mcal,              "MCAL",           float);
     60  GET_COLUMN (McalPSF,           "MCAL_PSF",       float);
     61  GET_COLUMN (McalAPER,          "MCAL_APER",      float);
    6162  GET_COLUMN (dMcal,             "MCAL_ERR",       float);
    6263  GET_COLUMN (dMagSys,           "MCAL_SYSERR",    float);
    63   GET_COLUMN (nFitPhotom,        "NFIT",             int);
    64   GET_COLUMN (flags,             "FLAGS",            int);
    65   GET_COLUMN (ubercalDist,       "UDIST",            int);
    66   GET_COLUMN (imageID,           "ID",               int);
    67   GET_COLUMN (Xm,                "CHISQ",          short);
     64  GET_COLUMN (McalChiSq,         "MCAL_CHISQ",     float);
     65  GET_COLUMN (nFitPhotom,        "NFIT",           int);
     66  GET_COLUMN (flags,             "FLAGS",          int);
     67  GET_COLUMN (ubercalDist,       "UDIST",          int);
     68  GET_COLUMN (imageID,           "ID",             int);
    6869
    6970  // free the memory associated with the FITS files
     
    7576  ALLOCATE (image_mags, ImageMag, Nrow);
    7677  for (i = 0; i < Nrow; i++) {
    77     image_mags[i].Mcal                      = Mcal       [i];
     78    image_mags[i].McalPSF                   = McalPSF    [i];
     79    image_mags[i].McalAPER                  = McalAPER   [i];
    7880    image_mags[i].dMcal                     = dMcal      [i];
    7981    image_mags[i].dMagSys                   = dMagSys    [i];
    80     image_mags[i].Xm                        = Xm         [i];
     82    image_mags[i].McalChiSq                 = McalChiSq  [i];
    8183    image_mags[i].nFitPhotom                = nFitPhotom [i];
    8284    image_mags[i].flags                     = flags      [i];
     
    8688  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
    8789
    88   free (Mcal       );
     90  free (McalPSF    );
     91  free (McalAPER   );
    8992  free (dMcal      );
    9093  free (dMagSys    );
    91   free (Xm         );
     94  free (McalChiSq  );
    9295  free (nFitPhotom );
    9396  free (flags      );
     
    121124  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_MAGS");
    122125
    123   gfits_define_bintable_column (&theader, "E", "MCAL",           "cal offset",                 "magnitudes", 1.0, 0.0);
     126  gfits_define_bintable_column (&theader, "E", "MCAL_PSF",       "PSF cal offset",             "magnitudes", 1.0, 0.0);
     127  gfits_define_bintable_column (&theader, "E", "MCAL_APER",      "APER cal offset",            "magnitudes", 1.0, 0.0);
    124128  gfits_define_bintable_column (&theader, "E", "MCAL_ERR",       "cal error",                  "magnitudes", 1.0, 0.0);
    125129  gfits_define_bintable_column (&theader, "E", "MCAL_SYSERR",    "systematic error",           "magnitudes", 1.0, 0.0);
     130  gfits_define_bintable_column (&theader, "E", "MCAL_CHISQ",     "cal chisq",                  "unitless",   1.0, 0.0);
    126131  gfits_define_bintable_column (&theader, "J", "NFIT",           "number of fitted stars",     "unitless",   1.0, 0.0);
    127132  gfits_define_bintable_column (&theader, "J", "FLAGS",          "analysis flags",             "unitless",   1.0, 0.0);
    128133  gfits_define_bintable_column (&theader, "J", "UDIST",          "distance to ubercal images", "images",     1.0, 0.0);
    129134  gfits_define_bintable_column (&theader, "J", "ID",             "image ID",                   "unitless",   1.0, 0.0);
    130   gfits_define_bintable_column (&theader, "I", "CHISQ",          "cal chisq",                  "unitless",   1.0, FT_BZERO_INT16);
    131135
    132136  // generate the output array that carries the data
    133137  gfits_create_table (&theader, &ftable);
    134138
    135   float *Mcal        ;
     139  float *McalPSF     ;
     140  float *McalAPER    ;
    136141  float *dMcal       ;
    137142  float *dMagSys     ;
    138   float *Xm          ;
     143  float *McalChiSq   ;
    139144  int   *nFitPhotom  ;
    140145  int   *flags       ;
     
    143148
    144149  // create intermediate storage arrays
    145   ALLOCATE (Mcal        ,         float,          Nimage_mags);
     150  ALLOCATE (McalPSF     ,         float,          Nimage_mags);
     151  ALLOCATE (McalAPER    ,         float,          Nimage_mags);
    146152  ALLOCATE (dMcal       ,         float,          Nimage_mags);
    147153  ALLOCATE (dMagSys     ,         float,          Nimage_mags);
    148   ALLOCATE (Xm          ,         float,          Nimage_mags);
     154  ALLOCATE (McalChiSq   ,         float,          Nimage_mags);
    149155  ALLOCATE (nFitPhotom  ,           int,          Nimage_mags);
    150156  ALLOCATE (flags       ,           int,          Nimage_mags);
     
    154160  // assign the storage arrays
    155161  for (i = 0; i < Nimage_mags; i++) {
    156     Mcal       [i]   = image_mags[i].Mcal       ;
     162    McalPSF    [i]   = image_mags[i].McalPSF    ;
     163    McalAPER   [i]   = image_mags[i].McalAPER   ;
    157164    dMcal      [i]   = image_mags[i].dMcal      ;
    158165    dMagSys    [i]   = image_mags[i].dMagSys    ;
    159     Xm         [i]   = image_mags[i].Xm         ;
     166    McalChiSq  [i]   = image_mags[i].McalChiSq  ;
    160167    nFitPhotom [i]   = image_mags[i].nFitPhotom ;
    161168    flags      [i]   = image_mags[i].flags      ;
     
    165172
    166173  // add the columns to the output array
    167   gfits_set_bintable_column (&theader, &ftable, "MCAL",           Mcal       ,         Nimage_mags);
     174  gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",       McalPSF    ,         Nimage_mags);
     175  gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",      McalAPER   ,         Nimage_mags);
    168176  gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",       dMcal      ,         Nimage_mags);
    169177  gfits_set_bintable_column (&theader, &ftable, "MCAL_SYSERR",    dMagSys    ,         Nimage_mags);
    170   gfits_set_bintable_column (&theader, &ftable, "CHISQ",          Xm         ,         Nimage_mags);
     178  gfits_set_bintable_column (&theader, &ftable, "MCAL_CHISQ",     McalChiSq  ,         Nimage_mags);
    171179  gfits_set_bintable_column (&theader, &ftable, "NFIT",           nFitPhotom ,         Nimage_mags);
    172180  gfits_set_bintable_column (&theader, &ftable, "FLAGS",          flags      ,         Nimage_mags);
     
    174182  gfits_set_bintable_column (&theader, &ftable, "ID",             imageID    ,         Nimage_mags);
    175183
    176   free (Mcal       );
     184  free (McalPSF    );
     185  free (McalAPER   );
    177186  free (dMcal      );
    178187  free (dMagSys    );
    179   free (Xm         );
     188  free (McalChiSq  );
    180189  free (nFitPhotom );
    181190  free (flags      );
  • trunk/Ohana/src/relphot/src/ImageOps.c

    r39643 r40291  
    143143    image[i].photom_map_id = input[i].photom_map_id;
    144144    image[i].flags         = input[i].flags        ;
    145     image[i].Mcal          = input[i].Mcal         ;
     145    image[i].McalPSF       = input[i].McalPSF      ;
     146    image[i].McalAPER      = input[i].McalAPER     ;
    146147    image[i].dMcal         = input[i].dMcal        ;
    147148    image[i].tzero         = input[i].tzero        ;
     
    179180    subset[i].photom_map_id = image[i].photom_map_id;
    180181    subset[i].flags         = image[i].flags        ;
    181     subset[i].Mcal          = image[i].Mcal         ;
     182    subset[i].McalPSF       = image[i].McalPSF      ;
     183    subset[i].McalAPER      = image[i].McalAPER     ;
    182184    subset[i].dMcal         = image[i].dMcal        ;
    183185    subset[i].tzero         = image[i].tzero        ;
     
    430432}
    431433
    432 // returns image.Mcal
     434// returns image.McalPSF or image.McalAPER
    433435// NOTE: static flat-field component is included in measure.Mflat
    434 float getMcal (off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog) {
    435   OHANA_UNUSED_PARAM(flatcorr);
    436   OHANA_UNUSED_PARAM(catalog);
    437 
    438   off_t i;
    439   float value;
     436float getMcal (off_t meas, int cat, dvoMagClassType class) {
     437
     438  off_t i;
    440439
    441440  i = MeasureToImage[cat][meas];
    442   if (i == -1) return (NAN);
    443 
    444   if (image[i].flags & IMAGE_BAD) return (NAN); 
    445   value = image[i].Mcal;
    446 
    447   // to do this, I need to pass in the catalog and flatcorr pointers
    448   // int flat_id = image[i].photom_map_id;
    449   // float offset = 0.0;
    450   // if (flat_id) {
    451   //   offset = FlatCorrectionOffset (flatcorr, flat_id, catalog[cat].measureT[meas].Xccd, catalog[cat].measureT[meas].Yccd);
    452   // }
    453   // value -= offset;
    454 
    455   return (value);
    456 }
    457 
    458 // returns image.Mcal - ff(x,y)
    459 // NOTE: static flat-field component is included in measure.Mflat
    460 float getMcal_alt (off_t meas, int cat, FlatCorrectionTable *flatcorr, float Xccd, float Yccd) {
    461   OHANA_UNUSED_PARAM(flatcorr);
    462   OHANA_UNUSED_PARAM(Xccd);
    463   OHANA_UNUSED_PARAM(Yccd);
    464 
    465   off_t i;
    466   float value;
    467 
    468   i = MeasureToImage[cat][meas];
    469   if (i == -1) return (NAN);
    470 
    471   if (image[i].flags & IMAGE_BAD) return (NAN); 
    472   value = image[i].Mcal;
    473 
    474   // to do this, I need to pass in the catalog and flatcorr pointers
    475   // int flat_id = image[i].photom_map_id;
    476   // float offset = 0.0;
    477   // if (flat_id) {
    478   //   offset = FlatCorrectionOffset (flatcorr, flat_id, Xccd, Yccd);
    479   // }
    480   // value -= offset;
    481 
    482   return (value);
    483 }
    484 
    485 // returns image.Mcal - ff(x,y)
     441  if (i == -1) return NAN;
     442
     443  if (image[i].flags & IMAGE_BAD) return NAN; 
     444
     445  switch (class) {
     446    case MAG_CLASS_PSF:
     447      return image[i].McalPSF;
     448    case MAG_CLASS_APER:
     449    case MAG_CLASS_KRON:
     450      return image[i].McalAPER;
     451    default:
     452      return NAN;
     453  }
     454  return NAN; // should not be able to reach here
     455}
     456
    486457short getUbercalDist (off_t meas, int cat) {
    487458
     
    499470}
    500471
    501 // returns image.Mcal - ff(x,y)
    502472float getCenterOffset (off_t meas, int cat, Measure *measure, unsigned int *myID) {
    503473
     
    519489}
    520490
    521 // returns image.Mcal - ff(x,y)
    522491int MatchImageName (off_t meas, int cat, char *name) {
    523492
     
    542511}
    543512
    544 // returns image.Mcal - ff(x,y)
    545513int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) {
    546514
     
    563531}
    564532
    565 // returns image.Mcal - ff(x,y)
    566533int FindImageSkycellID (off_t meas, int cat, int *myTessID, int *myProjectionID, int *mySkycellID) {
    567534
     
    618585void setMcal (Catalog *catalog, int PoorImages, FlatCorrectionTable *flatcorr) {
    619586
    620   off_t i, j, m, c, n, Nmax;
     587  off_t i, j, m, c, n;
    621588  int mark, bad, Nfew, Nbad, Nmos, Nrel, Ngrid, Nsys;
    622   float Msys, Mrel, Mmos, Mgrid, Mflat;
    623   // double *list, *dlist, *Mlist, *dMlist;
    624589
    625590  StatType stats;
     
    638603  }
    639604
    640   Nmax = 0;
     605  off_t Nmax = 0;
    641606  for (i = 0; i < Nimage; i++) {
    642607    Nmax = MAX (Nmax, N_onImage[i]);
    643608  }
    644   StatDataSet *refStars = StatDataSetAlloc (1, Nmax);
     609
     610  StatDataSet *kronStars   = StatDataSetAlloc (1, Nmax);
     611  StatDataSet *psfStars    = StatDataSetAlloc (1, Nmax);
    645612  StatDataSet *brightStars = StatDataSetAlloc (1, Nmax);
    646613
     
    676643    int minUbercalDist = 1000;
    677644   
    678     off_t Nref = 0;  // total number of reference stars on the image
    679     int Nbright = 0; // number of stars to measure the bright-end scatter
     645    off_t Nref = 0;    // number of stars used to measure McalPSF
     646    int   Nkron = 0;   // number of stars to measure McalAPER
     647    int   Nbright = 0; // number of stars to measure the bright-end scatter
    680648
    681649    if (N_onImage[i] == 0) {
     
    693661          continue;
    694662      }
    695       Mmos  = getMmos  (m, c);
     663      float Mmos  = getMmos  (m, c);
    696664      if (isnan(Mmos)) {
    697665          Nmos ++;
    698666          continue;
    699667      }
    700       Mgrid = getMgrid (m, c);
     668      float Mgrid = getMgrid (m, c);
    701669      if (isnan(Mgrid)) {
    702670          Ngrid++;
    703671          continue;
    704672      }
    705       Mrel  = getMrel  (catalog, m, c);
    706       if (isnan(Mrel)) {
     673
     674      // Mrel* is the average magnitude for this star.  For PS1 stacks, we have too much
     675      // PSF variability.  We need to calibrate the PSF magnitudes separately from the
     676      // Aperture-like magnitues.  (We have an option to use the kron magnitudes or the
     677      // other apertures here).  I basically need to do this analysis separately for each
     678      // magnitude type
     679
     680      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     681      if (isnan(MrelPSF)) {
    707682          Nrel ++;
    708683          continue;
     
    714689      // the flat-correction.  NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat)
    715690
    716       Mflat = getMflat (m, c, flatcorr, catalog);
     691      float Mflat = getMflat (m, c, flatcorr, catalog);
    717692
    718693      n = catalog[c].measureT[m].averef;
    719       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    720       if (isnan(Msys)) {
     694      float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     695      if (isnan(MsysPSF)) {
    721696        Nsys++;
    722697        continue;
     
    731706
    732707    skip:
    733       refStars->flxlist[Nref] = Msys - Mrel - Mmos - Mgrid + Mflat;
    734       refStars->errlist[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    735       refStars->wgtlist[Nref] = 1;
    736       refStars->msklist[Nref] = 0;
    737       if (fabs(refStars->flxlist[Nref]) > 0.03) {
     708      psfStars->flxlist[Nref] = MsysPSF - MrelPSF - Mmos - Mgrid + Mflat;
     709      psfStars->errlist[Nref] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     710      psfStars->wgtlist[Nref] = 1;
     711      psfStars->msklist[Nref] = 0;
     712      if (fabs(psfStars->flxlist[Nref]) > 0.03) {
    738713        // fprintf (stderr, "deviant\n");
    739714      }
    740715
     716      float MrelKron = getMrel  (catalog, m, c, MAG_CLASS_KRON, MAG_SRC_CHP);
     717      float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON);
     718
     719      if (isfinite(MrelKron) && isfinite(MsysKron)) {
     720        kronStars->flxlist[Nkron] = MsysKron - MrelKron - Mmos - Mgrid + Mflat;
     721        kronStars->errlist[Nkron] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     722        kronStars->wgtlist[Nkron] = 1;
     723        kronStars->msklist[Nkron] = 0;
     724        Nkron ++;
     725      }
     726
    741727      if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) {
    742         fprintf (stderr, "%1d, %3d : %3d, %3d : %10.6f %10.6f : %6.3f  %6.3f  %6.3f  %6.3f  %6.3f : %6.3f\n", (int) i, (int) j, (int) c, (int) m, catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys, Mrel, Mmos, Mgrid, Mflat, refStars->flxlist[Nref]);
     728        fprintf (stderr, "%1d, %3d : %3d, %3d : %10.6f %10.6f : %6.3f  %6.3f  %6.3f  %6.3f  %6.3f : %6.3f\n", (int) i, (int) j, (int) c, (int) m, catalog[c].averageT[n].R, catalog[c].averageT[n].D, MsysKron, MrelKron, Mmos, Mgrid, Mflat, kronStars->flxlist[Nref]);
    743729      }
    744730
    745731      if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    746         brightStars->flxlist[Nbright] = refStars->flxlist[Nref];
    747         brightStars->errlist[Nbright] = refStars->errlist[Nref];
     732        brightStars->flxlist[Nbright] = psfStars->flxlist[Nref];
     733        brightStars->errlist[Nbright] = psfStars->errlist[Nref];
    748734        brightStars->wgtlist[Nbright] = 1;
    749735        brightStars->msklist[Nbright] = 0;
     
    770756    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
    771757# if (BASIC_STATS)
    772     liststats (refStars->flxlist, refStars->errlist, NULL, Nref, &stats);
     758    liststats (psfStars->flxlist, psfStars->errlist, NULL, Nref, &stats);
    773759# else
    774     liststats_irls (refStars, Nref, &stats);
     760    liststats_irls (psfStars, Nref, &stats);
    775761# endif
    776     image[i].Mcal       = stats.mean;
     762    image[i].McalPSF    = stats.mean;
    777763    image[i].dMcal      = stats.error;
    778764    image[i].nFitPhotom = Nref;
    779     image[i].Xm         = 100.0*log10(stats.chisq);
     765    image[i].McalChiSq  = stats.chisq;
    780766    Ncalibrated ++;
     767
     768    // no additional weight modification (we treat all stars on an image equally -- note an image is either ubercal-tied or not)
     769# if (BASIC_STATS)
     770    liststats (kronStars->flxlist, kronStars->errlist, NULL, Nkron, &stats);
     771# else
     772    liststats_irls (kronStars, Nref, &stats);
     773# endif
     774    image[i].McalAPER   = stats.mean;
    781775
    782776    if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) {
    783777      for (j = 0; j < Nref; j++) {
    784         fprintf (stderr, "%1d, %8d : %6.3f  %6.3f  %6.3f  %d\n", (int) i, (int) image[i].imageID, refStars->flxlist[j], refStars->errlist[j], refStars->wgtlist[j], refStars->msklist[j]);
     778        fprintf (stderr, "%1d, %8d : %6.3f  %6.3f  %6.3f  %d\n", (int) i, (int) image[i].imageID, kronStars->flxlist[j], kronStars->errlist[j], kronStars->wgtlist[j], kronStars->msklist[j]);
    785779      }
    786780    }
    787781
    788782    if ((image[i].imageID == TEST_IMAGE1) || (image[i].imageID == TEST_IMAGE2)) {
    789       fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal, image[i].dMcal);
     783      fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal);
    790784    }
    791785
    792786    if (!mark && VERBOSE_IMAGE) {
    793       fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal, image[i].dMcal);
     787      fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal);
    794788    }
    795789
    796790    if (PLOTSTUFF) {
    797       fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].Mcal, image[i].dMcal);
    798       plot_setMcal (refStars->flxlist, Nref, &stats, CLOUD_TOLERANCE);
     791      fprintf (stderr, "Mcal for : %s : %7.4f %7.4f\n", image[i].name, image[i].McalAPER, image[i].dMcal);
     792      plot_setMcal (psfStars->flxlist, Nref, &stats, CLOUD_TOLERANCE);
    799793    }
    800794
     
    803797    image[i].dMagSys = stats.sigma;
    804798
    805     if (image[i].Mcal < -CLOUD_TOLERANCE) {
    806       image[i].Mcal = 0.0;
     799    if (image[i].McalPSF < -CLOUD_TOLERANCE) {
     800      image[i].McalPSF = 0.0;
    807801    }
    808802
     
    813807
    814808  StatDataSetFree (brightStars, 1);
    815   StatDataSetFree (refStars, 1);
     809  StatDataSetFree (kronStars, 1);
     810  StatDataSetFree (psfStars, 1);
    816811
    817812  fprintf (stderr, "%d images calibrated\n", Ncalibrated);
     
    848843    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    849844
    850     mlist[N] = image[i].Mcal;
     845    mlist[N] = image[i].McalPSF;
    851846    slist[N] = image[i].dMcal;
    852847    dlist[N] = 1;
     
    873868    mark = FALSE;
    874869    image[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
    875     mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].Mcal - MedOffset) > MaxOffset);
     870    mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].McalPSF - MedOffset) > MaxOffset);
    876871    if (mark) {
    877872      Nmark ++;
     
    961956    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    962957
    963     Mlist[Nplot] = image[i].Mcal;
     958    Mlist[Nplot] = image[i].McalPSF;
    964959    dlist[Nplot] = image[i].dMcal;
    965960    xlist[Nplot] = image[i].secz;
    966961    minAirmass = MIN (image[i].secz, minAirmass);
    967962    maxAirmass = MAX (image[i].secz, maxAirmass);
    968     minMcal = MIN (image[i].Mcal, minMcal);
    969     maxMcal = MAX (image[i].Mcal, maxMcal);
     963    minMcal = MIN (image[i].McalPSF, minMcal);
     964    maxMcal = MAX (image[i].McalPSF, maxMcal);
    970965    mindMcal = MIN (image[i].dMcal, mindMcal);
    971966    maxdMcal = MAX (image[i].dMcal, maxdMcal);
     
    10511046      c = ImageToCatalog[i][j];
    10521047
    1053       Mcal  = getMcal  (m, c, flatcorr, catalog);
     1048      Mcal  = getMcal  (m, c, MAG_CLASS_PSF);
    10541049      if (isnan(Mcal)) continue;
    10551050      Mmos  = getMmos  (m, c);
     
    10921087    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    10931088
    1094     list[n] = pow (10.0, 0.01*image[i].Xm);
     1089    list[n] = image[i].McalChiSq;
    10951090    dlist[n] = 1;
    10961091    n++;
     
    11251120    if (FREEZE_IMAGES && isGPC1chip(image[i].photcode)) continue;
    11261121
    1127     list[n] = image[i].Mcal;
     1122    list[n] = image[i].McalPSF;
    11281123    dlist[n] = 1;
    11291124    n++;
     
    11701165  return (stats);
    11711166}
     1167
     1168void clearImages (void) {
     1169  image = NULL;
     1170}
     1171
     1172void checkImages (char *name) {
     1173
     1174  off_t i;
     1175  fprintf (stderr, "--- %s ---\n", name);
     1176 
     1177  OhanaMemblock *ref = (OhanaMemblock *) image - 1;
     1178  fprintf (stderr, "file: %s\n", ref->file);
     1179
     1180  fprintf (stderr, "0x%08llx \n", (unsigned long long) image);
     1181
     1182  for (i = 0; i < Nimage; i++) {
     1183    fprintf (stderr, "%s : 0x%08x : %6.3f  %6.3f\n", image[i].name, image[i].flags, image[i].McalPSF, image[i].McalAPER);
     1184  }
     1185}
  • trunk/Ohana/src/relphot/src/ImageSubset.c

    r39478 r40291  
    6363  char type[16];
    6464
    65   GET_COLUMN (Mcal,      "MCAL",         float);
     65  GET_COLUMN (McalPSF,   "MCAL_PSF",     float);
     66  GET_COLUMN (McalAPER,  "MCAL_APER",    float);
    6667  GET_COLUMN (dMcal,     "MCAL_ERR",     float);
    6768  GET_COLUMN (imageID,   "IMAGE_ID",     int);
     
    7980  ALLOCATE (image, ImageSubset, Nrow);
    8081  for (i = 0; i < Nrow; i++) {
    81     image[i].Mcal          = Mcal[i];
     82    image[i].McalPSF       = McalPSF[i];
     83    image[i].McalAPER      = McalAPER[i];
    8284    image[i].dMcal         = dMcal[i];
    8385    image[i].imageID       = imageID[i];
     
    9395  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
    9496
    95   free (Mcal);
     97  free (McalPSF);
     98  free (McalAPER);
    9699  free (dMcal);
    97100  free (imageID);
     
    136139  gfits_create_table_header (&theader, "BINTABLE", "IMAGE_SUBSET");
    137140
    138   gfits_define_bintable_column (&theader, "E", "MCAL",         "zero point offset", "magnitudes", 1.0, 0.0);
     141  gfits_define_bintable_column (&theader, "E", "MCAL_PSF",     "zero point offset", "magnitudes", 1.0, 0.0);
     142  gfits_define_bintable_column (&theader, "E", "MCAL_APER",    "zero point offset", "magnitudes", 1.0, 0.0);
    139143  gfits_define_bintable_column (&theader, "E", "MCAL_ERR",     "zero point error",  "magnitudes", 1.0, 0.0);
    140144  gfits_define_bintable_column (&theader, "J", "IMAGE_ID",     "image ID",          NULL,         1.0, FT_BZERO_INT32);
     
    151155  gfits_create_table (&theader, &ftable);
    152156
    153   float *Mcal, *dMcal;
     157  float *McalPSF, *McalAPER, *dMcal;
    154158  unsigned int *imageID, *map, *flags, *tzero;
    155159  int *tessID, *projID, *skycellID;
     
    158162
    159163  // create intermediate storage arrays
    160   ALLOCATE (Mcal,      float,          Nimage);
     164  ALLOCATE (McalPSF,   float,          Nimage);
     165  ALLOCATE (McalAPER,  float,          Nimage);
    161166  ALLOCATE (dMcal,     float,          Nimage);
    162167  ALLOCATE (imageID,   unsigned int,   Nimage);
     
    172177  // assign the storage arrays
    173178  for (i = 0; i < Nimage; i++) {
    174     Mcal[i]      = image[i].Mcal;
     179    McalPSF[i]   = image[i].McalPSF;
     180    McalAPER[i]  = image[i].McalAPER;
    175181    dMcal[i]     = image[i].dMcal;
    176182    imageID[i]   = image[i].imageID;
     
    186192
    187193  // add the columns to the output array
    188   gfits_set_bintable_column (&theader, &ftable, "MCAL",         Mcal,      Nimage);
     194  gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",     McalPSF,   Nimage);
     195  gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",    McalAPER,  Nimage);
    189196  gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",     dMcal,     Nimage);
    190197  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",     imageID,   Nimage);
     
    198205  gfits_set_bintable_column (&theader, &ftable, "UBERCAL_DIST", ucdist,    Nimage);
    199206
    200   free (Mcal);
     207  free (McalPSF);
     208  free (McalAPER);
    201209  free (dMcal);
    202210  free (imageID);
  • trunk/Ohana/src/relphot/src/MosaicOps.c

    r39632 r40291  
    111111   
    112112    /* a new mosaic, define ranges -- preserve the original values incase this image is not used */
    113     mosaic[Nmosaic].start  = start;
    114     mosaic[Nmosaic].stop   = stop;
    115     mosaic[Nmosaic].Mcal   = 0.0; // note : mosaic stores only offsets relative to the original image values
    116     mosaic[Nmosaic].dMcal  = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
    117     mosaic[Nmosaic].dMsys  = 0.0;
    118     mosaic[Nmosaic].Xm = 0.0;
    119     mosaic[Nmosaic].flags  = image[i].flags;
    120     mosaic[Nmosaic].secz   = image[i].secz;
    121     mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     113    mosaic[Nmosaic].start     = start;
     114    mosaic[Nmosaic].stop      = stop;
     115    mosaic[Nmosaic].McalPSF   = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     116    mosaic[Nmosaic].McalAPER  = 0.0; // note : mosaic stores only offsets relative to the original image values
     117    mosaic[Nmosaic].dMcal     = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     118    mosaic[Nmosaic].dMsys     = 0.0;
     119    mosaic[Nmosaic].McalChiSq = 0.0;// NAN or 0.0?
     120    mosaic[Nmosaic].flags     = image[i].flags;
     121    mosaic[Nmosaic].secz      = image[i].secz;
     122    mosaic[Nmosaic].photcode  = GetPhotcodeEquivCodebyCode (image[i].photcode);
    122123
    123124    // XXX do we need to do something about flag consistency across a mosaic?
     
    208209  for (i = 0; i < Nmosaic; i++) {
    209210    /* a new mosaic, define ranges */
    210     mosaic[i].start    = startTimesMosaic[i];
    211     mosaic[i].stop     = 0;
    212     mosaic[i].Mcal     = 0.0;
    213     mosaic[i].dMcal    = 0.0;
    214     mosaic[i].dMsys    = 0.0;
    215     mosaic[i].Xm       = 0.0;
    216     mosaic[i].flags    = 0;
    217     mosaic[i].secz     = NAN;
    218     mosaic[i].photcode = 0;
    219     mosaic[i].skipCal  = FALSE;
     211    mosaic[i].start     = startTimesMosaic[i];
     212    mosaic[i].stop      = 0;
     213    mosaic[i].McalPSF   = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     214    mosaic[i].McalAPER  = 0.0; // note : mosaic stores only offsets relative to the original image values
     215    mosaic[i].dMcal     = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     216    mosaic[i].dMsys     = 0.0;
     217    mosaic[i].McalChiSq = 0.0;// NAN or 0.0?
     218    mosaic[i].flags     = 0;
     219    mosaic[i].secz      = NAN;
     220    mosaic[i].photcode  = 0;
     221    mosaic[i].skipCal   = FALSE;
    220222   
    221223    memset (&mosaic[i].coords, 0, sizeof(Coords));
     
    294296      abort();
    295297    }
    296     mosaic[j].stop     = stop;
    297     mosaic[j].Mcal     = 0.0;
    298     mosaic[j].dMcal    = 0.0;
    299     mosaic[j].Xm       = 0.0;
    300     mosaic[j].dMsys    = subset[i].flags;
    301     mosaic[j].flags    = subset[i].flags;
    302     mosaic[j].secz     = subset[i].secz;
    303     mosaic[j].photcode = GetPhotcodeEquivCodebyCode (subset[i].photcode);
     298    mosaic[j].stop      = stop;
     299
     300    mosaic[j].McalPSF   = 0.0;
     301    mosaic[j].McalAPER  = 0.0;
     302    mosaic[j].dMcal     = 0.0;
     303    mosaic[j].McalChiSq = 0.0;
     304
     305    mosaic[j].dMsys     = subset[i].flags;
     306    mosaic[j].flags     = subset[i].flags;
     307    mosaic[j].secz      = subset[i].secz;
     308    mosaic[j].photcode  = GetPhotcodeEquivCodebyCode (subset[i].photcode);
    304309  }
    305310
     
    377382  // init the mosaic array values
    378383  for (i = 0; i < Nmosaic; i++) {
    379     mosaic[i].start    = startTimesMosaic[i];
    380     mosaic[i].stop     = 0;
    381     mosaic[i].Mcal     = 0.0;
    382     mosaic[i].dMcal    = 0.0;
    383     mosaic[i].dMsys    = 0.0;
    384     mosaic[i].Xm       = 0.0;
    385     mosaic[i].flags    = 0;
    386     mosaic[i].secz     = NAN;
    387     mosaic[i].photcode = 0;
    388     mosaic[i].skipCal  = FALSE;
     384    mosaic[i].start     = startTimesMosaic[i];
     385    mosaic[i].stop      = 0;
     386    mosaic[i].McalPSF   = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     387    mosaic[i].McalAPER  = 0.0; // note : mosaic stores only offsets relative to the original image values
     388    mosaic[i].dMcal     = 0.0; // note : at the end, mosaic.Mcal is added back to the input images
     389    mosaic[i].dMsys     = 0.0;
     390    mosaic[i].McalChiSq = 0.0;// NAN or 0.0?
     391    mosaic[i].flags     = 0;
     392    mosaic[i].secz      = NAN;
     393    mosaic[i].photcode  = 0;
     394    mosaic[i].skipCal   = FALSE;
    389395   
    390396    memset (&mosaic[i].coords, 0, sizeof(Coords));
     
    438444    }
    439445    mosaic[j].stop     = stop;
    440     mosaic[j].Mcal     = 0.0;
    441     mosaic[j].dMcal    = 0.0;
    442     mosaic[j].Xm       = 0.0;
    443     mosaic[j].dMsys    = image[i].flags;
    444     mosaic[j].flags    = image[i].flags;
    445     mosaic[j].secz     = image[i].secz;
    446     mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     446    mosaic[j].McalPSF   = 0.0;
     447    mosaic[j].McalAPER  = 0.0;
     448    mosaic[j].dMcal     = 0.0;
     449    mosaic[j].McalChiSq = 0.0;
     450    mosaic[j].dMsys     = image[i].flags;
     451    mosaic[j].flags     = image[i].flags;
     452    mosaic[j].secz      = image[i].secz;
     453    mosaic[j].photcode  = GetPhotcodeEquivCodebyCode (image[i].photcode);
    447454  }
    448455  MARKTIME("assign images to mosaic: %f sec\n", dtime);
     
    594601    mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
    595602
    596     mosaic[i].Mcal   = 0.0;
    597     mosaic[i].dMcal  = 0.0;
    598     mosaic[i].Xm     = 0.0;
     603    mosaic[i].McalPSF   = 0.0;
     604    mosaic[i].McalAPER  = 0.0;
     605    mosaic[i].dMcal     = 0.0;
     606    mosaic[i].dMsys     = 0.0;
     607    mosaic[i].McalChiSq = 0.0;
    599608  }
    600609  return;
     
    612621  double dS, dX, dY;
    613622  double R, D, Rmin, Rmax, Dmin, Dmax;
    614   double Mcal, dMcal, Xm;
     623  double McalPSF, McalAPER, dMcal, McalChiSq;
    615624
    616625  fprintf (stderr, "*** moving Mcal from image.Mcal to mosaic.Mcal ***\n");
     
    621630    Dmax = Rmax = -360.0;
    622631    dS = 0.0;
    623     Mcal = dMcal = Xm = 0;
     632    McalPSF = McalAPER = dMcal = McalChiSq = 0;
    624633    for (j = 0; j < MosaicN_Image[i]; j++) {
    625634      m = MosaicToImage[i][j];
     
    678687      // if it helps, note that ubercal uses a single zp per exposure, so the mean of those values is the same as the value
    679688
    680       Mcal  += image[m].Mcal;
    681       dMcal += image[m].dMcal;
    682       Xm    += image[m].Xm;
    683 
    684       image[m].Mcal   = 0.0;
    685       image[m].dMcal  = NAN;
    686       image[m].Xm     = NAN_S_SHORT;
     689      McalPSF   += image[m].McalPSF;
     690      McalAPER  += image[m].McalAPER;
     691      dMcal     += image[m].dMcal;
     692      McalChiSq += image[m].McalChiSq;
     693
     694      image[m].McalPSF   = 0.0;
     695      image[m].McalAPER  = 0.0;
     696      image[m].dMcal     = NAN;
     697      image[m].McalChiSq = NAN;
    687698    }
    688699    dS /= MosaicN_Image[i];
     
    696707    RD_to_XY (&dX, &dY, Rmax, Dmax, &mosaic[i].coords);
    697708
    698     mosaic[i].Mcal   = Mcal / MosaicN_Image[i];
    699     mosaic[i].dMcal  = dMcal / MosaicN_Image[i];
    700     mosaic[i].Xm     = Xm / MosaicN_Image[i];
     709    mosaic[i].McalPSF   = McalPSF / MosaicN_Image[i];
     710    mosaic[i].McalAPER  = McalAPER / MosaicN_Image[i];
     711    mosaic[i].dMcal     = dMcal / MosaicN_Image[i];
     712    mosaic[i].McalChiSq = McalChiSq / MosaicN_Image[i];
    701713  }
    702714  if (!USE_GRID) return;
     
    724736    for (j = 0; j < MosaicN_Image[i]; j++) {
    725737      im = MosaicToImage[i][j];
    726       image[im].Mcal += mosaic[i].Mcal;
    727       image[im].dMcal = mosaic[i].dMcal;
    728       image[im].Xm = mosaic[i].Xm;
     738      image[im].McalPSF    += mosaic[i].McalPSF;
     739      image[im].McalAPER   += mosaic[i].McalAPER;
     740      image[im].dMcal       = mosaic[i].dMcal;
     741      image[im].McalChiSq   = mosaic[i].McalChiSq;
    729742      image[im].ubercalDist = mosaic[i].ubercalDist;
    730       image[im].dMagSys = mosaic[i].dMsys;
    731       image[im].nFitPhotom = mosaic[i].nFitPhotom;
    732       image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW);
    733       image[im].flags |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR);
    734     }
    735     mosaic[i].Mcal = 0.0;
     743      image[im].dMagSys     = mosaic[i].dMsys;
     744      image[im].nFitPhotom  = mosaic[i].nFitPhotom;
     745      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_PHOTOM_FEW);
     746      image[im].flags      |= (mosaic[i].flags & ID_IMAGE_PHOTOM_POOR);
     747    }
     748    mosaic[i].McalPSF  = 0.0;
     749    mosaic[i].McalAPER = 0.0;
    736750  }     
    737751}
     
    886900
    887901  if (mosaic[i].flags & IMAGE_BAD) return (NAN); 
    888   value = mosaic[i].Mcal;
     902  value = mosaic[i].McalPSF;
    889903  return (value);
    890904}
     
    911925  off_t Nmax;
    912926  int PoorImages;
    913   double *list;
    914   double *dlist;
    915   double *Mlist;
    916   double *dMlist;
     927  double *psfMagList;
     928  double *psfErrList;
     929  double *brightMagList;
     930  double *brightErrList;
     931  double *kronMagList;
     932  double *kronErrList;
    917933} SetMmosInfo;
    918934
     
    945961
    946962  if (allocLists) {
    947     ALLOCATE (info->list, double, Nmax);
    948     ALLOCATE (info->dlist, double, Nmax);
    949     ALLOCATE (info->Mlist, double, Nmax);
    950     ALLOCATE (info->dMlist, double, Nmax);
     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);
    951969  }
    952970}
    953971
    954972void SetMmosInfoFree (SetMmosInfo *info) {
    955   free (info->list);
    956   free (info->dlist);
    957   free (info->Mlist);
    958   free (info->dMlist);
     973  free (info->psfMagList   );
     974  free (info->psfErrList   );
     975  free (info->kronMagList  );
     976  free (info->kronErrList  );
     977  free (info->brightMagList);
     978  free (info->brightErrList);
    959979}
    960980
     
    10571077  liststats_setmode (&stats, "INNER_WTMEAN");
    10581078
    1059   double *list   = info->list;
    1060   double *dlist  = info->dlist;
    1061   double *Mlist  = info->Mlist;
    1062   double *dMlist = info->dMlist;
     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;
    10631085
    10641086  assert (Nmos >= 0);
     
    11251147  int N = 0;
    11261148  for (j = 0; j < N_onMosaic[Nmos]; j++) {
    1127     float Msys, Mrel, Mcal, Mgrid, Mflat;
    11281149     
    11291150    off_t m = MosaicToMeasure[Nmos][j];
    11301151    off_t c = MosaicToCatalog[Nmos][j];
    11311152     
     1153    // NOTE : we are only using Mcal == McalPSF in this function; we set McalAPER to McalPSF
    11321154    if (fout) {
    1133       Mcal  = getMcal  (m, c, flatcorr, catalog);
    1134       Mgrid = getMgrid (m, c);
    1135       Mrel  = getMrel  (catalog, m, c);
    1136       Mflat = getMflat (m, c, flatcorr, catalog);
     1155      float Mcal     = getMcal  (m, c, MAG_CLASS_PSF);
     1156      float Mgrid    = getMgrid (m, c);
     1157      float MrelPSF  = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     1158      float Mflat    = getMflat (m, c, flatcorr, catalog);
    11371159
    11381160      off_t n = catalog[c].measureT[m].averef;
    1139       Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    1140 
    1141       float delta = Msys - Mrel - Mcal - Mgrid + Mflat;
     1161      float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1162
     1163      float delta = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
    11421164
    11431165      int isBad = (catalog[c].measureT[m].dbFlags & MEAS_BAD);
    11441166
    1145       fprintf (fout, "%f %f : %f %f %f %f %f  : %f %d\n", catalog[c].averageT[n].R, catalog[c].averageT[n].D, Msys, Mrel, Mcal, Mgrid, Mflat, delta, isBad);
     1167      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);
    11461168    }
    11471169
     
    11501172      continue;
    11511173    }
    1152     Mcal  = getMcal  (m, c, flatcorr, catalog);
     1174    float Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    11531175    if (isnan(Mcal)) {
    11541176      info->Ncal++;
    11551177      continue;
    11561178    }
    1157     Mgrid = getMgrid (m, c);
     1179    float Mgrid = getMgrid (m, c);
    11581180    if (isnan(Mgrid)) {
    11591181      info->Ngrid ++;
    11601182      continue;
    11611183    }
    1162     Mrel  = getMrel  (catalog, m, c);
    1163     if (isnan(Mrel)) {
     1184
     1185    // Mrel* is the average magnitude for this star.  For PS1 stacks, we have too much
     1186    // PSF variability.  We need to calibrate the PSF magnitudes separately from the
     1187    // Aperture-like magnitues.  (We have an option to use the kron magnitudes or the
     1188    // other apertures here).  I basically need to do this analysis separately for each
     1189    // magnitude type
     1190   
     1191    float MrelPSF = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
     1192    if (isnan(MrelPSF)) {
    11641193      info->Nrel ++;
    11651194      continue;
    11661195    }
     1196    float MrelKron = getMrel  (catalog, m, c, MAG_CLASS_KRON, MAG_SRC_CHP);
    11671197     
    11681198    // image.Mcal is not supposed to include the flat-field correction, so we need to
     
    11711201    // the flat-correction.  NOTE the sign of Mflat (Image.Mcal = Measure.Mcal - Mflat)
    11721202
    1173     Mflat = getMflat (m, c, flatcorr, catalog);
     1203    float Mflat = getMflat (m, c, flatcorr, catalog);
    11741204
    11751205    off_t n = catalog[c].measureT[m].averef;
    1176     Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
    1177     if (isnan(Msys)) {
     1206    float MsysPSF = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_PSF);
     1207    if (isnan(MsysPSF)) {
    11781208      info->Nsys++;
    11791209      continue;
    11801210    }
     1211    float MsysKron = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt], MAG_CLASS_KRON);
    11811212
    11821213    PhotCode *code = GetPhotcodebyCode (catalog[c].measureT[m].photcode);
     
    11931224    assert (Nbright >= 0);
    11941225
    1195     list[N]  = Msys - Mrel - Mcal - Mgrid + Mflat;
    1196     dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     1226    psfMagList[N]  = MsysPSF - MrelPSF - Mcal - Mgrid + Mflat;
     1227    psfErrList[N]  = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     1228    kronMagList[N] = MsysKron - MrelKron - Mcal - Mgrid + Mflat;
     1229    kronErrList[N] = psfErrList[N];
    11971230    if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    1198       Mlist[Nbright] = list[N];
    1199       dMlist[Nbright] = dlist[N];
     1231      brightMagList[Nbright] = psfMagList[N];
     1232      brightErrList[Nbright] = psfErrList[N];
    12001233      Nbright ++;
    12011234    }
     
    12231256  }
    12241257
    1225   liststats (list, dlist, NULL, N, &stats);
     1258  liststats (psfMagList, psfErrList, NULL, N, &stats);
    12261259  if (VERBOSE2 && info->PoorImages) fprintf (stderr, "Mmos: %f %f %d %d\n", stats.mean, stats.sigma, stats.Nmeas, N);
    12271260
    1228   myMosaic[0].Mcal  = stats.mean;
    1229   myMosaic[0].dMcal = stats.error;
     1261  // for now, I have no reason to measure these separately for camera-level images
     1262  myMosaic[0].McalPSF    = stats.mean;
     1263  myMosaic[0].dMcal      = stats.error;
     1264  myMosaic[0].McalChiSq  = stats.chisq;
    12301265  myMosaic[0].nFitPhotom = N;
    1231   myMosaic[0].Xm    = 100.0*log10(stats.chisq);
     1266
     1267  liststats (kronMagList, kronErrList, NULL, N, &stats);
     1268  myMosaic[0].McalAPER   = stats.mean;
    12321269
    12331270  if (testImage) {
     
    12371274  if (PLOTSTUFF) {
    12381275    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);
    1239     plot_setMcal (list, N, &stats, CLOUD_TOLERANCE);
     1276    plot_setMcal (psfMagList, N, &stats, CLOUD_TOLERANCE);
    12401277  }
    12411278
    12421279  // bright end scatter
    1243   liststats (Mlist, dMlist, NULL, Nbright, &stats);
     1280  liststats (brightMagList, brightErrList, NULL, Nbright, &stats);
    12441281  myMosaic[0].dMsys = stats.sigma;
    12451282
    1246   if (myMosaic[0].Mcal < -CLOUD_TOLERANCE) {
    1247     myMosaic[0].Mcal = 0.0;
     1283  if (myMosaic[0].McalPSF < -CLOUD_TOLERANCE) {
     1284    myMosaic[0].McalPSF = 0.0;
    12481285  }
    12491286
    12501287  if (testImage) {
    1251     fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].Mcal, myMosaic[0].dMsys, pow (10.0, 0.01*myMosaic[0].Xm));
     1288    fprintf (stderr, "%f %f  :  %f\n", myMosaic[0].McalPSF, myMosaic[0].dMsys, myMosaic[0].McalChiSq);
    12521289  }
    12531290
     
    14271464    imageOffset[i] = 0.0;
    14281465
    1429     if (VERBOSE2 && (fabs(mosaic[i].Mcal) < CLOUD_TOLERANCE)) {
    1430       fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     1466    if (VERBOSE2 && (fabs(mosaic[i].McalPSF) < CLOUD_TOLERANCE)) {
     1467      fprintf (stderr, "cloud-free: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);
    14311468    }
    1432     if (VERBOSE2 && (mosaic[i].Mcal < -CLOUD_TOLERANCE)) {
    1433       imageOffset[i] = -mosaic[i].Mcal;
    1434       // NOTE the negative sign: down below, we are going to add in the negative of Mcal
     1469    if (VERBOSE2 && (mosaic[i].McalPSF < -CLOUD_TOLERANCE)) {
     1470      imageOffset[i] = -mosaic[i].McalPSF;
     1471      // NOTE the negative sign: down below, we are going to add in the negative of McalPSF
    14351472      // to this image, and the propagated mean values for other images
    1436       fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     1473      fprintf (stderr, "anti-clouds: %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);
    14371474    }
    1438     if (VERBOSE2 && (mosaic[i].Mcal > CLOUD_TOLERANCE)) {
    1439       fprintf (stderr, "cloudy    : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].Mcal);
     1475    if (VERBOSE2 && (mosaic[i].McalPSF > CLOUD_TOLERANCE)) {
     1476      fprintf (stderr, "cloudy    : %s : %f\n", image[MosaicToImage[i][0]].name, mosaic[i].McalPSF);
    14401477    }
    14411478  }
     
    15401577    }
    15411578
    1542     // a negative cloud image (cloud: Mcal > 0; anti-clouds: Mcal < 0; imageOffset = -Mcal)
     1579    // a negative cloud image (cloud: McalPSF > 0; anti-clouds: McalPSF < 0; imageOffset = -McalPSF)
    15431580    if (imageOffset[i] > 0.0) continue;
    15441581
     
    15641601  // find the images / mosaics with negative clouds and save their offset
    15651602  for (i = 0; i < Nmosaic; i++) {
    1566     mosaic[i].Mcal += imageOffset[i];
     1603    mosaic[i].McalPSF += imageOffset[i];
    15671604  }
    15681605
     
    16051642    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    16061643
    1607     list[n] = mosaic[i].Mcal;
     1644    list[n] = mosaic[i].McalPSF;
    16081645    dlist[n] = 1;
    16091646    n++;
     
    16771714      c = MosaicToCatalog[i][j];
    16781715
    1679       Mcal = getMcal  (m, c, flatcorr, catalog);
     1716      Mcal = getMcal  (m, c, MAG_CLASS_PSF);
    16801717      if (isnan(Mcal)) continue;
    16811718      Mgrid = getMgrid (m, c);
    16821719      if (isnan(Mgrid)) continue;
    1683       Mrel = getMrel  (catalog, m, c);
     1720      Mrel = getMrel  (catalog, m, c, MAG_CLASS_PSF, MAG_SRC_CHP);
    16841721      if (isnan(Mrel)) continue;
    16851722      N++;
     
    17191756    if (KEEP_UBERCAL && (mosaic[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) continue;
    17201757
    1721     list[n]  = pow (10.0, 0.01*mosaic[i].Xm);
     1758    list[n]  = mosaic[i].McalChiSq;
    17221759    dlist[n] = 1;
    17231760    n++;
     
    17511788    if (mosaic[i].flags & IMAGE_BAD) continue;
    17521789    if (mosaic[i].skipCal) continue;
    1753     mlist[N] = mosaic[i].Mcal;
     1790    mlist[N] = mosaic[i].McalPSF;
    17541791    slist[N] = mosaic[i].dMcal;
    17551792    dlist[N] = 1;
     
    17811818      Nscatter ++;
    17821819    }
    1783     if (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset) {
     1820    if (fabs(mosaic[i].McalPSF - MedOffset) > MaxOffset) {
    17841821      mark = TRUE;
    17851822      Noffset ++;
     
    18581895
    18591896  for (i = 0; i < Nmosaic; i++) {
    1860     Mlist[i] = mosaic[i].Mcal;
     1897    Mlist[i] = mosaic[i].McalPSF;
    18611898    dlist[i] = mosaic[i].dMcal;
    18621899    xlist[i] = mosaic[i].secz;
  • trunk/Ohana/src/relphot/src/StarOps.c

    r40019 r40291  
    3434
    3535
    36 float getMrel (Catalog *catalog, off_t meas, int cat) {
    37 
    38   int Nsec, Nsecfilt, photcode;
    39   int ave;
    40   float value;
    41 
    42   ave = catalog[cat].measureT[meas].averef;
    43   photcode = catalog[cat].measureT[meas].photcode;
     36//
     37float getMrel (Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source) {
     38
     39  int ave = catalog[cat].measureT[meas].averef;
     40  int photcode = catalog[cat].measureT[meas].photcode;
    4441
    4542  int ecode = GetPhotcodeEquivCodebyCode (photcode);
    46   Nsec = GetPhotcodeNsec(ecode);
    47   Nsecfilt = GetPhotcodeNsecfilt ();
     43  int Nsec = GetPhotcodeNsec(ecode);
     44  int Nsecfilt = GetPhotcodeNsecfilt ();
     45
     46  int entry = Nsecfilt*ave+Nsec;
     47
     48  SecFilt *secfilt = &catalog[cat].secfilt[entry];
    4849
    4950  // is this star OK?
    50   if (catalog[cat].secfilt[Nsecfilt*ave+Nsec].flags & STAR_BAD) return (NAN); 
    51  
    52   value = catalog[cat].secfilt[Nsecfilt*ave+Nsec].M;
    53   return (value);
     51  if (secfilt->flags & STAR_BAD) return (NAN); 
     52
     53  switch (class) {
     54    case MAG_CLASS_PSF:
     55      switch (source) {
     56        case MAG_SRC_CHP:
     57          return secfilt->MpsfChp;
     58        case MAG_SRC_WRP:
     59          return secfilt->MpsfWrp;
     60        case MAG_SRC_STK:
     61          return secfilt->MpsfStk;
     62        default:
     63          return NAN;
     64      }
     65      break;
     66    case MAG_CLASS_KRON:
     67      switch (source) {
     68        case MAG_SRC_CHP:
     69          return secfilt->MkronChp;
     70        case MAG_SRC_WRP:
     71          return secfilt->MkronWrp;
     72        case MAG_SRC_STK:
     73          return secfilt->MkronStk;
     74        default:
     75          return NAN;
     76      }
     77      break;
     78    case MAG_CLASS_APER:
     79      switch (source) {
     80        case MAG_SRC_CHP:
     81          return secfilt->MapChp;
     82        case MAG_SRC_WRP:
     83          return secfilt->MapWrp;
     84        case MAG_SRC_STK:
     85          return secfilt->MapStk;
     86        default:
     87          return NAN;
     88      }
     89      break;
     90    case MAG_CLASS_NONE:
     91    case MAG_CLASS_DEV: // DeVaucouleur Model (only for galphot)
     92    case MAG_CLASS_EXP: // Exponential Model (only for galphot)
     93    case MAG_CLASS_SER: // Sersic Model (only for galphot)
     94      return NAN;
     95      break;
     96  }
     97  return NAN; // should not be able to reach here
    5498}
    5599
     
    429473  int i;
    430474  off_t j, k, m;
    431   float Mcal, Mmos, Mgrid;
    432475
    433476  MEAS_BAD = ID_MEAS_NOCAL;
     
    440483      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
    441484        if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
    442         Mcal  = getMcal  (m, i, flatcorr, catalog);
    443         if (isnan(Mcal)) continue;
    444         Mmos  = getMmos  (m, i);
     485        float McalPSF  = getMcal  (m, i, MAG_CLASS_PSF);
     486        float McalAPER = getMcal  (m, i, MAG_CLASS_APER);
     487        if (isnan(McalPSF)) continue;
     488        float Mmos  = getMmos  (m, i);
    445489        if (isnan(Mmos)) continue;
    446         Mgrid = getMgrid (m, i);
     490        float Mgrid = getMgrid (m, i);
    447491        if (isnan(Mgrid)) continue;
     492
     493        // Note that this operation is setting measure->McalAPER to image->McalAPER only
     494        // for the stacks.  Elsewhere (setMrelCatalog) we are using image->McalPSF for all
     495        // types of measurements EXCEPT stacks.
     496
     497        // we need to use McalAPER for stacks (and only stacks)
     498        int useStackAper = !USE_MCAL_PSF_FOR_STACK_APER && isGPC1stack(catalog[i].measureT[m].photcode);
    448499
    449500        // note that measurements for which the image is not selected will not be modified
     
    451502
    452503        // set the output calibration
    453         catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid;
     504        catalog[i].measure[m].McalPSF  = McalPSF  + Mmos + Mgrid;
     505        catalog[i].measure[m].McalAPER = useStackAper ? McalAPER + Mmos + Mgrid : McalPSF  + Mmos + Mgrid;
    454506
    455507        if (catalog[i].measureT[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
    456           myAssert (isfinite(catalog[i].measure[m].Mcal), "oops, broke an ubercal mag");
     508          myAssert (isfinite(catalog[i].measure[m].McalPSF), "oops, broke an ubercal mag");
    457509        }
    458510      }
     
    501553}
    502554
     555int dumpMags (FILE *fout, Catalog *catalog, int Ncatalog) {
     556
     557  int i, n;
     558  off_t j;
     559
     560  int Nsecfilt = GetPhotcodeNsecfilt ();
     561
     562  for (i = 0; i < Ncatalog; i++) {
     563    for (j = 0; (j < catalog[i].Naverage) && (j < 2); j++) {
     564      fprintf (fout, "%08x %08x %10.6f %10.6f : \n", catalog[i].averageT[j].catID, catalog[i].averageT[j].objID, catalog[i].averageT[j].R, catalog[i].averageT[j].D);
     565      for (n = 0; n < 5; n++) {
     566        fprintf (fout, "secf  %5d | %6.3f %6.3f | %6.3f %6.3f | %6.3f %6.3f\n", n, catalog[i].secfilt[j*Nsecfilt + n].MpsfChp, catalog[i].secfilt[j*Nsecfilt + n].MkronChp, catalog[i].secfilt[j*Nsecfilt + n].MpsfStk, catalog[i].secfilt[j*Nsecfilt + n].MkronStk, catalog[i].secfilt[j*Nsecfilt + n].MpsfWrp, catalog[i].secfilt[j*Nsecfilt + n].MkronWrp);
     567      }
     568      int m = catalog[i].averageT[j].measureOffset;
     569      for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
     570        fprintf (fout, "meas %5d %5d | %6.3f %6.3f | %6.3f %6.3f\n", m+n, catalog[i].measureT[m+n].photcode, catalog[i].measureT[m+n].M, catalog[i].measureT[m+n].Mkron, catalog[i].measureT[m+n].McalPSF, catalog[i].measureT[m+n].McalAPER);
     571      }
     572    }
     573  }
     574  return TRUE;
     575}
     576
    503577void clean_stars (Catalog *catalog, int Ncatalog) {
    504578
     
    513587  if (VERBOSE) fprintf (stderr, "marking poor stars\n");
    514588
    515   /* find Xm median -> ChiSq lim must be > median */
     589  /* find Mchisq median -> ChiSq lim must be > median */
    516590  for (i = Ntot = 0; i < Ncatalog; i++) {
    517591    Ntot += catalog[i].Naverage;
     
    535609        if (isnan(Mchisq)) continue;
    536610        xlist[Ntot] = Mchisq;
    537         slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     611        slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp;
    538612        dlist[Ntot] = 1;
    539613        Ntot ++;
     
    551625    for (i = 0; i < Ncatalog; i++) {
    552626      for (j = 0; j < catalog[i].Naverage; j++) {
    553         dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     627        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp;
    554628        float Mchisq = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
    555629        mark = (dM > MaxScatter) || (isnan(Mchisq)) || (Mchisq > MaxChisq);
     
    578652// NSIGMA_REJECT (5) sigma of the mean
    579653
     654// this function only operations on the PSF magnitudes
     655
    580656# define NSIGMA_CLIP 3.0
    581657# define NSIGMA_REJECT 5.0
     
    644720         
    645721          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    646           Mcal  = getMcal  (m, i, flatcorr, catalog);
     722          Mcal  = getMcal  (m, i, MAG_CLASS_PSF);
    647723          if (isnan(Mcal)) { Ncal ++; continue; }
    648724          Mmos  = getMmos  (m, i);
     
    695771         
    696772          // NOTE: we do not skip MEAS_BAD because this measurement is just an internal assessment of the outliers
    697           Mcal  = getMcal  (m, i, flatcorr, catalog);
     773          Mcal  = getMcal  (m, i, MAG_CLASS_PSF);
    698774          if (isnan(Mcal)) continue;
    699775          Mmos  = getMmos  (m, i);
     
    776852        int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
    777853        if (ecode != seccode) { continue;}
    778         Mcal = getMcal  (m, i, flatcorr, catalog);
     854        Mcal = getMcal  (m, i, MAG_CLASS_PSF);
    779855        if (isnan(Mcal)) { continue;}
    780856        Mmos = getMmos  (m, i);
     
    865941      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
    866942
    867       dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     943      dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp;
    868944      if (isnan(dM)) continue;
    869945      list[n] = dM;
     
    906982      for (j = 0; j < catalog[i].Naverage; j++) {
    907983        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
    908         dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     984        dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dMpsfChp;
    909985        bin = dMrel / 0.00025;
    910986        bin = MAX (0, MIN (NBIN-1, bin));
     
    9461022      for (j = 0; j < catalog[i].Naverage; j++) {
    9471023        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
    948         xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
     1024        xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp;
    9491025        value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Mchisq;
    9501026        if (isnan((double)(value))) continue;
  • trunk/Ohana/src/relphot/src/args.c

    r39926 r40291  
    325325    remove_argument (N, &argc, argv);
    326326    CALIBRATE_STACKS_AND_WARPS = TRUE;
     327  }
     328  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     329  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     330    remove_argument (N, &argc, argv);
     331    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
    327332  }
    328333
     
    696701  }
    697702
     703  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     704  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     705    remove_argument (N, &argc, argv);
     706    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
     707  }
     708
    698709  /* define time */
    699710  TimeSelect = FALSE;
  • trunk/Ohana/src/relphot/src/bcatalog.c

    r39641 r40291  
    153153        if (subcatalog[0].measureT[Nmeasure].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
    154154          if (!KEEP_UBERCAL) {
    155             subcatalog[0].measureT[Nmeasure].Mcal = 0.0;
     155            subcatalog[0].measureT[Nmeasure].McalPSF  = 0.0;
     156            subcatalog[0].measureT[Nmeasure].McalAPER = 0.0;
    156157            subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;
    157158          }
    158159        } else {
    159160          if (getImageEntry (Nmeasure, Ncat) >= 0) {
    160             subcatalog[0].measureT[Nmeasure].Mcal = 0.0;
     161            subcatalog[0].measureT[Nmeasure].McalPSF  = 0.0;
     162            subcatalog[0].measureT[Nmeasure].McalAPER = 0.0;
    161163          }
    162164        }
  • trunk/Ohana/src/relphot/src/launch_region_hosts.c

    r39511 r40291  
    5858    strextend (&command, "-cloud-limit %f", CLOUD_TOLERANCE);
    5959
    60     if (VERBOSE)             strextend (&command, "-v");
    61     if (VERBOSE2)            strextend (&command, "-vv");
    62     if (RESET)               strextend (&command, "-reset");
    63     if (RESET_ZEROPTS)       strextend (&command, "-reset-zpts");
    64     if (!KEEP_UBERCAL)       strextend (&command, "-reset-ubercal");
    65     if (DophotSelect)        strextend (&command, "-dophot %d", DophotValue);
    66     if (ImagSelect)          strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
    67     if (MaxDensityUse)       strextend (&command, "-max-density %f", MaxDensityValue);
    68     if (SyntheticPhotometry) strextend (&command, "-synthphot");
    69     if (USE_BASIC_CHECK)     strextend (&command, "-basic-image-search");
     60    if (VERBOSE)                    strextend (&command, "-v");
     61    if (VERBOSE2)                   strextend (&command, "-vv");
     62    if (RESET)                      strextend (&command, "-reset");
     63    if (RESET_ZEROPTS)              strextend (&command, "-reset-zpts");
     64    if (!KEEP_UBERCAL)              strextend (&command, "-reset-ubercal");
     65    if (DophotSelect)               strextend (&command, "-dophot %d", DophotValue);
     66    if (ImagSelect)                 strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     67    if (MaxDensityUse)              strextend (&command, "-max-density %f", MaxDensityValue);
     68    if (SyntheticPhotometry)        strextend (&command, "-synthphot");
     69    if (USE_BASIC_CHECK)            strextend (&command, "-basic-image-search");
    7070
    71     if (UPDATE)              strextend (&command, "-update");
    72     if (MOSAIC_ZEROPT)       strextend (&command, "-mosaic");
    73     if (FREEZE_IMAGES)       strextend (&command, "-imfreeze");
    74     if (FREEZE_MOSAICS)      strextend (&command, "-mosfreeze");
    75     if (PARALLEL)            strextend (&command, "-parallel");
    76     if (PARALLEL_MANUAL)     strextend (&command, "-parallel-manual");
    77     if (PARALLEL_SERIAL)     strextend (&command, "-parallel-serial");
     71    if (UPDATE)                     strextend (&command, "-update");
     72    if (MOSAIC_ZEROPT)              strextend (&command, "-mosaic");
     73    if (FREEZE_IMAGES)              strextend (&command, "-imfreeze");
     74    if (FREEZE_MOSAICS)             strextend (&command, "-mosfreeze");
     75    if (CALIBRATE_STACKS_AND_WARPS) strextend (&command, "-only-stacks-and-warps");
     76    if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }
     77
     78    if (PARALLEL)                   strextend (&command, "-parallel");
     79    if (PARALLEL_MANUAL)            strextend (&command, "-parallel-manual");
     80    if (PARALLEL_SERIAL)            strextend (&command, "-parallel-serial");
    7881
    7982    // XXX deprecate this if we are happy with the new version
  • trunk/Ohana/src/relphot/src/liststats.c

    r39648 r40291  
    194194# define WEIGHT_THRESHOLD 0.3
    195195
    196 int fit_least_squares (double *fit, double *y, double *dy, double *wgt, double *wt, int Npts);
     196int fit_least_squares (double *fit, double *err, double *y, double *dy, double *wgt, double *wt, int Npts);
    197197double VectorFractionInterpolate (double *values, float fraction, int Npts);
    198198double weight_cauchy (double x);
     
    253253   
    254254    double oldValue = value;
    255     if (!fit_least_squares (&value, dataset->flxlist, dataset->errlist, dataset->wgtlist, dataset->wtvals, Npoints)) {
     255    if (!fit_least_squares (&value, NULL, dataset->flxlist, dataset->errlist, dataset->wgtlist, dataset->wtvals, Npoints)) {
    256256      value = oldValue;
    257257      break;
     
    330330    }
    331331
    332     if (!fit_least_squares (&value, dataset->ysample, dataset->dysample, dataset->wtsample, NULL, Nkeep)) continue;
     332    if (!fit_least_squares (&value, NULL, dataset->ysample, dataset->dysample, dataset->wtsample, NULL, Nkeep)) continue;
    333333
    334334    dataset->bvalue[Nboot] = value;
     
    342342  stats->error = (Shi - Slo) / 2.0;
    343343
     344  // bootstrap can sometimes yield an excessively-optimistic result for the error.  Do not let
     345  // the reported error be smaller than the formal error
     346  double errvalue;
     347  if (fit_least_squares (&value, &errvalue, dataset->ykeep, dataset->dykeep, dataset->wtkeep, NULL, Nkeep)) {
     348    stats->error = MAX (stats->error, errvalue);
     349  }
     350
    344351  return TRUE;
    345352}
    346353
    347354// wgt is externally-supplied weight, wt is optional
    348 int fit_least_squares (double *fit, double *y, double *dy, double *wgt, double *wt, int Npts) {
     355int fit_least_squares (double *fit, double *err, double *y, double *dy, double *wgt, double *wt, int Npts) {
    349356
    350357  int i;
     
    364371  }
    365372  if (S0 == 0.0) return FALSE;
    366   *fit = S1 / S0;
     373  *fit = S1  / S0;
     374  if (err) { *err = 1.0 / S0; }
    367375  return TRUE;
    368376}
  • trunk/Ohana/src/relphot/src/load_images.c

    r39642 r40291  
    5252      free (subset);
    5353      subset = image;
     54    }
     55  }
     56
     57  // reset image values as needed.  always allow 'few' images to succeed, if possible (new
     58  // images / detections may have been added
     59  for (off_t i = 0; i < Nsubset; i++) {
     60    if (subset[i].flags & ID_IMAGE_PHOTOM_FEW) {
     61      subset[i].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
     62    }
     63    if (RESET) {
     64      if (RESET_ZEROPTS) {
     65        if (!KEEP_UBERCAL || !(subset[i].flags & ID_IMAGE_PHOTOM_UBERCAL)) {
     66          subset[i].McalPSF  = 0.0;
     67          subset[i].McalAPER = 0.0;
     68          subset[i].dMcal    = NAN;
     69          subset[i].flags   &= ~ID_IMAGE_PHOTOM_UBERCAL;
     70        }
     71      }
     72      subset[i].flags &= ~ID_IMAGE_PHOTOM_POOR;
     73      subset[i].ubercalDist = 1000;
    5474    }
    5575  }
  • trunk/Ohana/src/relphot/src/plot_scatter.c

    r37037 r40291  
    4040
    4141                if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
    42                 Mcal = getMcal  (m, i, flatcorr, catalog);
     42                Mcal = getMcal  (m, i, MAG_CLASS_PSF);
    4343                if (isnan(Mcal)) continue;
    4444                Mmos = getMmos  (m, i);
     
    4747                if (isnan(Mgrid)) continue;
    4848
    49                 Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
     49                Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].MpsfChp;
    5050                if (isnan(Mrel)) continue;
    5151
  • trunk/Ohana/src/relphot/src/plotstuff.c

    r39457 r40291  
    179179
    180180  KapaInitGraph (graphdata);
    181   graphdata[0].style = 2;
     181  graphdata[0].style = KAPA_PLOT_POINTS; /* points */
    182182  graphdata[0].ptype = 2;
    183183  graphdata[0].ltype = 0;
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r39926 r40291  
    247247    if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); }
    248248    if (USE_BASIC_CHECK)   {  strextend (&command, "-basic-image-search"); }
     249    if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }
    249250
    250251    if (!(STAGES & STAGE_CHIP))  { strextend (&command, "-skip-chip"); }
  • trunk/Ohana/src/relphot/src/relphot_images.c

    r39643 r40291  
    4242  MARKTIME("-- load images: %f sec\n", dtime);
    4343
     44  // checkImages("load images");
     45
    4446  /* unlock, if we can (else, unlocked below) */
    4547  if (!UPDATE) dvo_image_unlock (&db);
    4648
    4749  // load the flat correction table (if defined)
     50  // we no longer need to do this: the flatcorrection is now saved in measure.Mflat
    4851# if (0)
    4952  char flatcorrfile[256];
     
    6063    /* add in a loop over the catalogs calling dvo_catalog_chipcoords */
    6164
     65    // checkImages("load catalog");
     66
    6267    /* match measurements with images, mosaics */
    6368    initImageBins  (catalog, Ncatalog, TRUE);
     
    7782
    7883    setExclusions (catalog, Ncatalog, TRUE);
     84    // checkImages("set Exclu");
    7985
    8086    global_stats (catalog, Ncatalog, flatcorr, 0);
     
    108114        plot_scatter (catalog, Ncatalog, flatcorr);
    109115      }
     116      if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
     117      // checkImages("start loop");
     118
    110119      setMrel  (catalog, Ncatalog, flatcorr); // threaded
     120      if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
     121      // checkImages("set Mrel");
     122
    111123      if (PLOTSTUFF) {
    112124        plot_scatter (catalog, Ncatalog, flatcorr);
    113125      }
    114126      setMcal  (catalog, FALSE, flatcorr);
     127      // checkImages("set Mcal");
     128      if (VERBOSE2) dumpMags (stderr, catalog, Ncatalog);
     129
    115130      setMmos  (catalog, FALSE, flatcorr);
    116131      setMgrid (catalog, flatcorr);
     
    213228        // ensure the db format is updated
    214229        dbX.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
     230        gfits_modify (&dbX.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT);
     231
    215232        char photcodeFile[1024];
    216233        sprintf (photcodeFile, "%s/Photcodes.dat", CATDIR);
     
    257274    // ensure the db format is updated
    258275    db.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
     276    gfits_modify (&db.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT);
    259277  }
    260278  if (CALIBRATE_STACKS_AND_WARPS || (NLOOP > 0)) {
  • trunk/Ohana/src/relphot/src/relphot_objects.c

    r39926 r40291  
    251251    if (USE_BASIC_CHECK)   { strextend (&command, "-basic-image-search"); }
    252252    if (USE_ALL_IMAGES)    { strextend (&command, "-use-all-images"); }
     253    if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }
    253254
    254255    if (!(STAGES & STAGE_CHIP))  { strextend (&command, "-skip-chip"); }
  • trunk/Ohana/src/relphot/src/relphot_parallel_images.c

    r39643 r40291  
    3636  client_logger_message ("loaded images\n");
    3737
    38   // once we have read this table, we should remove it for repeat runs
    39   // unlink (IMAGE_TABLE); // XXX a bit risky, add some protection?
    40 
    4138  makeMosaics (image, Nimage, TRUE);
    4239
     
    4441
    4542  // load the flat correction table (if defined)
     43  // we no longer need to do this: the flatcorrection is now saved in measure.Mflat
    4644# if (0)
    4745  char flatcorrfile[256];
     
    150148  client_logger_message ("all hosts are done the loops\n");
    151149
    152   /* set Mcal & Mmos for bad images */
    153   setMcal  (catalog, TRUE, flatcorr);
    154   setMmos  (catalog, TRUE, flatcorr);
     150  /* set Mcal & Mmos for bad images (for stack_and_warps, force images to be measured) */
     151  int onlyPoorImages = !CALIBRATE_STACKS_AND_WARPS;
     152  setMcal  (catalog, onlyPoorImages, flatcorr);
     153  setMmos  (catalog, onlyPoorImages, flatcorr);
    155154  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    156155
     
    171170  freeGridBins (Ncatalog);
    172171  freeImages((char *)image);
     172  free (image);
    173173
    174174  SkyListFree(skylist);
  • trunk/Ohana/src/relphot/src/relphot_parallel_regions.c

    r39643 r40291  
    5151    // ensure the db format is updated
    5252    db.format = dvo_catalog_catformat (UPDATE_CATFORMAT);
     53    gfits_modify (&db.header, "FORMAT", "%s", 1, UPDATE_CATFORMAT);
    5354  }
    5455
     
    8485
    8586  // save the changes to the image parameters
    86   dvo_image_save (&db, VERBOSE); // this function modifies the db.ftable.buffer: do not free stored Image table
     87  dvo_image_save (&db, VERBOSE);
     88
     89  // dvo_image_save frees db.ftable.buffer (== image) and replaces it: do not free stored Image table
     90  clearImages ();
     91
    8792  dvo_image_unlock (&db);
    8893  MARKTIME ("finished relphot -parallel-regions: %f sec total\n", dtime);
  • trunk/Ohana/src/relphot/src/relphot_synthphot_catalog.c

    r38062 r40291  
    9292      float *value = (float *) zpts->matrix[Nsec].buffer;
    9393      float ZP = !isnan(value[Npix]) ? value[Npix] : 0.0;
    94       secfilt[Nsec].M    = measure[measSYN[i]].M + ZP;
    95       secfilt[Nsec].dM  = 0.6;
    96       secfilt[Nsec].Mchisq = NAN;
    97       secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;
     94      secfilt[Nsec].MpsfChp = measure[measSYN[i]].M + ZP;
     95      secfilt[Nsec].dMpsfChp = 0.6;
     96      secfilt[Nsec].Mchisq   = NAN;
     97      secfilt[Nsec].flags   |= ID_SECF_USE_SYNTH;
    9898    }
    9999  }
  • trunk/Ohana/src/relphot/src/select_images.c

    r39648 r40291  
    251251    image[nimage] = timage[i];
    252252    inSubset[i] = TRUE;
    253     /* always allow 'few' images to succeed, if possible (new images / detections may have
    254      * been added) */
    255     if (image[nimage].flags & ID_IMAGE_PHOTOM_FEW) {
    256       image[nimage].flags &= ~(ID_IMAGE_PHOTOM_FEW | ID_IMAGE_PHOTOM_POOR);
    257     }
    258     if (RESET) {
    259       if (RESET_ZEROPTS) {
    260         if (!KEEP_UBERCAL || !(image[nimage].flags & ID_IMAGE_PHOTOM_UBERCAL)) {
    261           image[nimage].Mcal = 0.0;
    262           image[nimage].dMcal = NAN;
    263           image[nimage].flags &= ~ID_IMAGE_PHOTOM_UBERCAL;
    264         }
    265       }
    266       image[nimage].flags &= ~ID_IMAGE_PHOTOM_POOR;
    267       image[nimage].ubercalDist = 1000;
    268     }
    269253    line_number[nimage] = i;
    270254    nimage ++;
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r39926 r40291  
    22
    33# if (0)
    4 # define TEST_OBJ_ID 0x0000000e
    5 # define TEST_CAT_ID 0x000076ee
     4# define TEST_OBJ_ID 0x000098f9
     5# define TEST_CAT_ID 0x00005ad3
    66# else
    77# define TEST_OBJ_ID 0
     
    102102// 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
    103103// 4) some reference photcode of some kind can be specified as fixed and have a high weight
     104
     105// Although I calculate McalAPER for exposures, I am only using McalPSF for chips.  Note
     106// in StarOps.c:setMcalOutput I am setting measure->McalAPER to image->McalPSF for chips
     107// and warps, but not stacks
    104108
    105109// set mean of chip measurements (selected by photcode range for now):
     
    224228      // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
    225229      Mmos = Mgrid = 0;
    226       Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value
     230      Mcal = measureT[k].McalPSF; // check that this is zero for loaded REF value
    227231    } else {
    228       // getMcal_alt returns image[].Mcal modified by flatcorr(image.photom_map_id,x,y)
    229       // NOTE: getMcal_alt does not include measure.Mflat
    230       Mcal  = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd);
     232      // getMcal returns image[].Mcal; note the flat-field correction is stored in measure.Mflat
     233      Mcal  = getMcal (meas, cat, MAG_CLASS_PSF);
    231234      if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
    232235      Mmos  = getMmos  (meas, cat);
     
    268271    }
    269272
    270     float Mkron, dMkron;
     273    // NOTE: we need to calculate the averge chip Kron on each pass to be able to calibrate the stacks
     274    float Mkron = PhotCatTiny (&measureT[k], MAG_CLASS_KRON);
     275    float dMkron;
    271276    if (isSetMrelFinal) {
    272       Mkron = PhotCat (&measure[k], MAG_CLASS_KRON);
    273277      dMkron = MAX (hypot(measure[k].dMkron, code->photomErrSys), MIN_ERROR);
    274       if (CHECK_VALID_MAG(Mkron, dMkron)) {
    275         int Nkron = results->kronData[Nsec].Nlist;
    276         results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel
    277         results->kronData[Nsec].errlist[Nkron] = dMkron;
    278         results->kronData[Nsec].wgtlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
    279         results->kronData[Nsec].ranking[Nkron] = measureRank[k];
    280         results->kronData[Nsec].measSeq[Nkron] = k;
    281         results->kronData[Nsec].msklist[Nkron] = 0;
    282         results->kronData[Nsec].Nlist ++;
    283       }
     278    } else {
     279      dMkron = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
     280    }
     281    if (CHECK_VALID_MAG(Mkron, dMkron)) {
     282      int Nkron = results->kronData[Nsec].Nlist;
     283      results->kronData[Nsec].flxlist[Nkron] = Mkron - Mflat - Mcal - Mmos - Mgrid; // this is consistent with PhotRel
     284      results->kronData[Nsec].errlist[Nkron] = dMkron;
     285      results->kronData[Nsec].wgtlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0;
     286      results->kronData[Nsec].ranking[Nkron] = measureRank ? measureRank[k] : 0;
     287      results->kronData[Nsec].measSeq[Nkron] = k;
     288      results->kronData[Nsec].msklist[Nkron] = 0;
     289      results->kronData[Nsec].Nlist ++;
    284290    }
    285291
     
    377383        }
    378384      }
    379       secfilt[Nsec].M      = Mpsf + ZP;
    380       secfilt[Nsec].dM    = 0.6;
    381       secfilt[Nsec].Mchisq = 0.0;
    382       secfilt[Nsec].flags |= ID_SECF_USE_SYNTH;
     385      secfilt[Nsec].MpsfChp  = Mpsf + ZP;
     386      secfilt[Nsec].dMpsfChp = 0.6;
     387      secfilt[Nsec].Mchisq   = 0.0;
     388      secfilt[Nsec].flags   |= ID_SECF_USE_SYNTH;
    383389      continue;
    384390    }
     
    386392    // if too few valid measurements meet the minimum criteria, go to the next entry
    387393    StatType *psfstats = &results->psfstats;
    388     int Nranking = MAG_STATS_BY_RANKING (&results->psfData[Nsec], psfstats);
    389     if (Nranking < Nminmeas) {
     394    int NrankingPSF = MAG_STATS_BY_RANKING (&results->psfData[Nsec], psfstats);
     395    if (NrankingPSF < Nminmeas) {
    390396      secfilt[Nsec].flags |= ID_OBJ_FEW;
    391397    } else {
    392       secfilt[Nsec].M    = psfstats->mean;
    393       secfilt[Nsec].dM   = psfstats->error;
    394       secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
    395     }
    396     int minRankPSF = (Nranking > 0) ? results->psfData[Nsec].ranking[0] : 10;
     398      secfilt[Nsec].MpsfChp  = psfstats->mean;
     399      secfilt[Nsec].dMpsfChp = psfstats->error;
     400      secfilt[Nsec].Mchisq   = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN;
     401    }
    397402
    398403    // when running -averages, we have no information about the images, so we cannot set this
     
    401406    }
    402407
     408    StatType *kronstats = &results->kronstats;
     409    int NrankingKRON = MAG_STATS_BY_RANKING (&results->kronData[Nsec], kronstats);
     410    if (NrankingKRON) {
     411      secfilt[Nsec].MkronChp  = kronstats->mean;
     412      secfilt[Nsec].dMkronChp = kronstats->error;
     413      secfilt[Nsec].sMkronChp = kronstats->sigma;
     414      secfilt[Nsec].NusedKron = NrankingKRON;
     415    }
     416
    403417    if (isSetMrelFinal) {
    404418      if ((average[0].objID == TEST_OBJ_ID) && (average[0].catID == TEST_CAT_ID)) {
     
    406420      }
    407421
    408       // mark the measurements matching this ranking
    409       markMeasureByRanking (&results->psfData[Nsec], measure, minRankPSF, ID_MEAS_PHOTOM_PSF, ID_MEAS_MASKED_PSF);
    410 
    411       if (Nranking) {
    412         secfilt[Nsec].Mstdev = psfstats->sigma;
    413         secfilt[Nsec].Nused  = psfstats->Nmeas;
    414         secfilt[Nsec].Mmax   = psfstats->max;
    415         secfilt[Nsec].Mmin   = psfstats->min;
     422      if (NrankingPSF) {
     423        secfilt[Nsec].sMpsfChp = psfstats->sigma;
     424        secfilt[Nsec].Nused    = psfstats->Nmeas;
     425        secfilt[Nsec].Mmax     = psfstats->max;
     426        secfilt[Nsec].Mmin     = psfstats->min;
    416427      }
    417428      secfilt[Nsec].psfQfMax     = results->psfQfMax[Nsec];
     
    421432      MAX_NOT_NAN (psfQfPerfMax, secfilt[Nsec].psfQfPerfMax);
    422433
     434      // mark the measurements matching this ranking
     435      int minRankPSF = (NrankingPSF > 0) ? results->psfData[Nsec].ranking[0] : 10;
     436      markMeasureByRanking (&results->psfData[Nsec], measure, minRankPSF, ID_MEAS_PHOTOM_PSF, ID_MEAS_MASKED_PSF);
     437
     438      int minRankKron = (NrankingKRON > 0) ? results->kronData[Nsec].ranking[0] : 10;
     439      markMeasureByRanking (&results->kronData[Nsec], measure, minRankKron, ID_MEAS_PHOTOM_KRON, ID_MEAS_MASKED_KRON);
     440
    423441      StatType *apstats = &results->apstats;
    424       Nranking = MAG_STATS_BY_RANKING (&results->aperData[Nsec], apstats);
    425       if (Nranking) {
    426         secfilt[Nsec].Map     = apstats->mean;
    427         secfilt[Nsec].dMap    = apstats->error;
    428         secfilt[Nsec].sMap    = apstats->sigma;
    429         secfilt[Nsec].NusedAp = Nranking;
    430       }
    431       int minRankAper = (Nranking > 0) ? results->aperData[Nsec].ranking[0] : 10;
     442      int NrankingAPER = MAG_STATS_BY_RANKING (&results->aperData[Nsec], apstats);
     443      if (NrankingAPER) {
     444        secfilt[Nsec].MapChp  = apstats->mean;
     445        secfilt[Nsec].dMapChp = apstats->error;
     446        secfilt[Nsec].sMapChp = apstats->sigma;
     447        secfilt[Nsec].NusedAp = NrankingAPER;
     448      }
     449      int minRankAper = (NrankingAPER > 0) ? results->aperData[Nsec].ranking[0] : 10;
    432450      markMeasureByRanking (&results->aperData[Nsec], measure, minRankAper, ID_MEAS_PHOTOM_APER, ID_MEAS_MASKED_APER);
    433 
    434       StatType *kronstats = &results->kronstats;
    435       Nranking = MAG_STATS_BY_RANKING (&results->kronData[Nsec], kronstats);
    436       if (Nranking) {
    437         secfilt[Nsec].Mkron     = kronstats->mean;
    438         secfilt[Nsec].dMkron    = kronstats->error;
    439         secfilt[Nsec].sMkron    = kronstats->sigma;
    440         secfilt[Nsec].NusedKron = Nranking;
    441       }
    442       int minRankKron = (Nranking > 0) ? results->kronData[Nsec].ranking[0] : 10;
    443       markMeasureByRanking (&results->kronData[Nsec], measure, minRankKron, ID_MEAS_PHOTOM_KRON, ID_MEAS_MASKED_KRON);
    444451
    445452      // does this object appear extended in > 50% of measurements?
     
    518525// 2) select the BEST detections per filter (regardless of PRIMARY)
    519526// 3) apply the zero point and AB->Jy transformations
     527
     528// I calculate McalAPER and McalPSF independently for stacks.  I use McalAPER for Mkron
     529// and Map, and McalPSF for Mpsf.  Note in StarOps.c:setMcalOutput I am setting
     530// measure->McalAPER to image->McalPSF for chips and warps, but not stacks
     531
    520532int setMrelAverageStack (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr) {
    521533
     
    528540  SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt];
    529541
    530   off_t k;
    531 
    532   float Mcal = 0, Mmos = 0, Mgrid = 0, Finst = 0;
     542  float McalPSF = 0, McalAPER = 0, Mmos = 0, Mgrid = 0;
    533543
    534544  // set the primary projection cell and skycell for this coordinate
     
    546556  int haveStackObject = FALSE;
    547557
    548   int Ns;
    549   for (Ns = 0; Ns < Nphotcodes; Ns++) {
     558  for (int Ns = 0; Ns < Nphotcodes; Ns++) {
    550559
    551560    int thisCode = photcodes[Ns][0].code;
     
    556565    int haveStack = FALSE;
    557566
    558     float psfQFbest = 0.0;
    559 
    560     off_t stackBestMeasure = -1;
    561     off_t stackPrimaryMeasure = -1;
    562 
    563567    int isBad = FALSE;
    564568    int isSuspect = FALSE;
    565569
    566     int Nstack = 0; // number for this photcode
    567     int NstackDet = 0; // number for this photcode
    568 
     570    int NstackMeas = 0; // number of stack measurements for this photcode
     571    int NstackDet  = 0; // number of stack detections for this photcode (not forced)
     572
     573    int   primaryLevelMax = 0;
     574    off_t primaryEntryMax = -1;
     575    float primaryValueMax = 0.0;
     576
     577    int   bestLevelMax = 0;
     578    off_t bestEntryMax = -1;
     579    float bestValueMax = 0.0;
     580
     581    int Nprimary = 0;
     582
     583    // reset all stack-related values for this secfilt:
    569584    secfilt[Nsec].stackBestOff = -1;
    570585    secfilt[Nsec].stackPrmryOff = -1;
    571 
    572     off_t meas = measureOffset;
    573     for (k = 0; k < Nmeasure; k++, meas++) {
     586    secfilt[Nsec].FpsfStk   = NAN;
     587    secfilt[Nsec].dFpsfStk  = NAN;
     588    secfilt[Nsec].FkronStk  = NAN;
     589    secfilt[Nsec].dFkronStk = NAN;
     590    secfilt[Nsec].FapStk    = NAN;
     591    secfilt[Nsec].dFapStk   = NAN;
     592    secfilt[Nsec].MpsfStk   = NAN;
     593    secfilt[Nsec].MkronStk  = NAN;
     594    secfilt[Nsec].MapStk    = NAN;
     595    secfilt[Nsec].Nstack    = 0;
     596    secfilt[Nsec].NstackDet = 0;
     597    secfilt[Nsec].flags    &= ~ID_SECF_STACK_FLAGS; // reset the stack flags
     598
     599    for (off_t k = 0; k < Nmeasure; k++) {
    574600
    575601      // only examine gpc1 stack data
     
    581607      if (code->equiv != thisCode) { continue; }
    582608
    583       Nstack ++;
    584       if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++;
     609      NstackMeas ++;
     610      if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++; // 0x04 = PM_SOURCE_MODE2_MATCHED
    585611
    586612      // clear this bit for all measurements
     
    590616      haveStack = TRUE;
    591617      haveStackObject = TRUE;
     618
     619      // if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
     620
     621      int isPrimary = FALSE;
    592622     
    593       // ** find the PRIMARY measurement
    594 
    595       // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the
    596       // primary skycell for this position
    597       if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    598         stackPrimaryMeasure = k;
     623      // ** is this a PRIMARY measurement? (there may be more than one)
     624
     625      // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement
     626      // is from the primary skycell for this position. (note that MatchImageSkycellID
     627      // requires the entry in the full Measure table, not just this object)
     628      if (MatchImageSkycellID (measureOffset + k, cat, tessID, projectID, skycellID)) {
    599629        measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY;
    600         secfilt[Nsec].stackPrmryOff = meas;
    601         myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range");
    602       }
    603 
    604       // ** now choose the BEST measurements (may also be PRIMARY)
    605 
    606       // ensure that we at least have a single best measure
    607       if (stackBestMeasure == -1) stackBestMeasure = k;
    608 
    609       // choose the best psfQFperf value for the BEST measurement
    610       if (isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > psfQFbest)) {
    611         psfQFbest = measure[k].psfQFperf;
    612         stackBestMeasure = k;
    613       }
    614       // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary.
    615       if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.98)) {
    616         psfQFbest = 1000; // force this to be the best entry
    617         stackBestMeasure = k;
    618       }
    619 
    620       if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad);
    621 
     630        isPrimary = TRUE;
     631        Nprimary ++;
     632      }
     633
     634      // soften the error floor (can dM be 0.0?)
     635      int SNvalue = isfinite(measure[k].dM) ? 1.0 / hypot (measure[k].dM, MIN_ERROR) : NAN;
     636      int psfQFperfAboveLimit = isfinite(SNvalue) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95);
     637
     638      // ** determine the BEST level
     639      int bestLevel = 0;
     640      if (!isPrimary && !psfQFperfAboveLimit) bestLevel = 1;
     641      if ( isPrimary && !psfQFperfAboveLimit) bestLevel = 2;
     642      if (!isPrimary &&  psfQFperfAboveLimit) bestLevel = 3;
     643      if ( isPrimary &&  psfQFperfAboveLimit) bestLevel = 4;
     644
     645      // here is the rule for choosing the best value:
     646      float bestValue = (bestLevel > 2) ? SNvalue : measure[k].psfQFperf;
     647
     648      // if we have not reached this level before, set the new level
     649      if (bestLevelMax < bestLevel) {
     650        bestValueMax = bestValue;
     651        bestLevelMax = bestLevel;
     652        bestEntryMax = k;
     653      }
     654      // if we have reached this level before, set the new value if we beat the old one
     655      if ((bestLevelMax == bestLevel) && (bestValueMax < bestValue)) {
     656        bestValueMax = bestValue;
     657        bestEntryMax = k;
     658      }
     659      myAssert (bestEntryMax > -1, "this should not happen");
     660
     661      // ** determine the PRIMARY level
     662      int primaryLevel = 0;
     663      if ( isPrimary && !psfQFperfAboveLimit) primaryLevel = 1;
     664      if ( isPrimary &&  psfQFperfAboveLimit) primaryLevel = 2;
     665
     666      // here is the rule for choosing the PRIMARY value:
     667      float primaryValue = 0.0;
     668      if (primaryLevel == 1) { primaryValue = measure[k].psfQFperf; }
     669      if (primaryLevel == 2) { primaryValue = SNvalue; }
     670
     671      // if we have not reached this level before, set the new level
     672      if (isPrimary && (primaryLevelMax < primaryLevel)) {
     673        primaryValueMax = primaryValue;
     674        primaryLevelMax = primaryLevel;
     675        primaryEntryMax = k;
     676      }
     677      // if we have reached this level before, set the new value if we beat the old one
     678      if (isPrimary && (primaryLevelMax == primaryLevel) && (primaryValueMax < primaryValue)) {
     679        primaryValueMax = primaryValue;
     680        primaryEntryMax = k;
     681      }
     682    }
     683
     684    // if we do not have a stack measurement for this photcode, skip everything below
     685    if (!haveStack) continue;
     686 
     687    // now we have a BEST and a PRIMARY entry (may be the same entry)
     688
     689    off_t meas = bestEntryMax;
     690    off_t measSeq = meas + measureOffset;
     691
     692    myAssert (meas >= 0, "this should not happen");
     693
     694    // measurements without an image are either external reference photometry or
     695    // data for which the associated image has not been loaded (probably because of
     696    // overlaps).  we only want measurements associated with stack images in this loop
     697   
     698    // match measurement to its image (this is just a check, right?)
     699    if (getImageEntry (measSeq, cat) < 0) {
    622700      // measurements without an image are either external reference photometry or
    623701      // data for which the associated image has not been loaded (probably because of
    624       // overlaps).  we only want measurements associated with stack images in this loop
    625 
    626       // match measurement to its image (this is just a check, right?)
    627       if (getImageEntry (meas, cat) < 0) {
    628         // measurements without an image are either external reference photometry or
    629         // data for which the associated image has not been loaded (probably because of
    630         // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
    631         Mmos = Mgrid = 0;
    632         Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
    633       } else {
    634         Mcal  = getMcal_alt  (meas, cat, flatcorr, measure[k].Xccd, measure[k].Yccd);
    635         if (isnan(Mcal))  SKIP_THIS_MEAS_STACK(Ncal);
    636         Mmos  = getMmos  (meas, cat);
    637         if (isnan(Mmos))  SKIP_THIS_MEAS_STACK(Nmos);
    638         Mgrid = getMgrid (meas, cat);
    639         if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid);
    640       }
    641 
    642       // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
    643       Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF);
    644       if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
    645 
    646       // data quality assessment
    647       isBad |= (measure[k].photFlags & code->photomBadMask);
    648       isBad |= (measure[k].psfQF < 0.85);
    649       isBad |= isnan(measure[k].psfQF);
    650       isBad |= measure[k].dM > 0.2; // S/N < 5.0
    651 
    652       isSuspect |= (measure[k].photFlags & code->photomPoorMask);
    653       isSuspect |= (measure[k].psfQFperf < 0.85);
    654     }
    655 
    656     if (!haveStack) continue;
    657 
    658     if (!isSuspect && !isBad) {
    659       NstackGood ++;
    660     }
    661     if (isSuspect && !isBad) {
    662       NstackSuspect ++;
    663     }
    664 
    665     // measurements which are bad will not have a valid stack entry and are skipped
    666     k = (stackBestMeasure >= 0) ? stackBestMeasure : stackPrimaryMeasure;
    667     if (k < 0) continue;
    668 
    669     // we are now populating stackDetectID not stack Image ID in secfilt
    670     // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin      : stackCenterIDmin;
    671     // ID = measure[k].extID; // for the stack, this is the stackDetectID
    672 
    673     // get the zero point for the selected image
    674     float zp = PhotZeroPoint (&measure[k], &average[0], &secfilt[0]) - (Mcal + Mmos + Mgrid);
     702      // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
     703      McalPSF  = measure[meas].McalPSF; // check that this is zero for loaded REF value
     704      McalAPER = McalPSF; // check that this is zero for loaded REF value
     705      Mmos     = 0.0;
     706      Mgrid    = 0.0;
     707    } else {
     708      McalPSF   = getMcal  (measSeq, cat, MAG_CLASS_PSF);
     709      McalAPER  = USE_MCAL_PSF_FOR_STACK_APER ? getMcal  (measSeq, cat, MAG_CLASS_PSF) : getMcal  (measSeq, cat, MAG_CLASS_KRON);
     710      Mmos      = getMmos  (measSeq, cat);
     711      Mgrid     = getMgrid (measSeq, cat);
     712    }
     713   
     714    // ** Here is the math to relate mag,zp to flux
    675715
    676716    // flux_cgs : erg sec^1 cm^-2 Hz^-1
     
    703743    // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56)
    704744
     745    // get the zero point for the selected image
     746    // Use a different zero point for the PSF-like and APERTURE-like magnitudes
     747    float zpPSF  = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalPSF  + Mmos + Mgrid);
     748    float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid);
     749
    705750    // zpFactor to go from instrumental flux to Janskies
    706     float zpFactor = pow(10.0, -0.4*zp + 3.56);
     751    float zpFactorPSF  = pow(10.0, -0.4*zpPSF  + 3.56);
     752    float zpFactorAPER = pow(10.0, -0.4*zpAPER + 3.56);
    707753
    708754    // need to put in AB mag factor to get to Janskies (or uJy?)
    709     secfilt[Nsec].FpsfStk   = zpFactor * measure[k].FluxPSF; 
    710     secfilt[Nsec].dFpsfStk  = zpFactor * measure[k].dFluxPSF;
    711     secfilt[Nsec].FkronStk  = zpFactor * measure[k].FluxKron;
    712     secfilt[Nsec].dFkronStk = zpFactor * measure[k].dFluxKron;
    713     secfilt[Nsec].FapStk    = zpFactor * measure[k].FluxAp;
     755    secfilt[Nsec].FpsfStk   = zpFactorPSF  * measure[meas].FluxPSF; 
     756    secfilt[Nsec].dFpsfStk  = zpFactorPSF  * measure[meas].dFluxPSF;
     757    secfilt[Nsec].FkronStk  = zpFactorAPER * measure[meas].FluxKron;
     758    secfilt[Nsec].dFkronStk = zpFactorAPER * measure[meas].dFluxKron;
     759    secfilt[Nsec].FapStk    = zpFactorAPER * measure[meas].FluxAp;
    714760
    715761    // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245).  we are going to
    716762    // use PSF flux error instead here:
    717     // secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxAp;
    718     secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxPSF;
     763    // secfilt[Nsec].dFapStk   = zpFactorAPER * measure[meas].dFluxAp;
     764    secfilt[Nsec].dFapStk   = zpFactorAPER * measure[meas].dFluxPSF;
    719765
    720766    // Jy to AB mags
    721     secfilt[Nsec].MpsfStk   = (measure[k].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN;
    722     secfilt[Nsec].MkronStk  = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
    723     secfilt[Nsec].MapStk    = (measure[k].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN;
    724 
    725     secfilt[Nsec].stackBestOff = k + measureOffset;
     767    secfilt[Nsec].MpsfStk   = (measure[meas].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk)  : NAN;
     768    secfilt[Nsec].MkronStk  = (measure[meas].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
     769    secfilt[Nsec].MapStk    = (measure[meas].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk)   : NAN;
     770
     771    // record the measurement which gave the best value
     772    secfilt[Nsec].stackBestOff = (bestEntryMax == -1) ? -1 : bestEntryMax + measureOffset;
    726773    myAssert (secfilt[Nsec].stackBestOff <= catalog[0].Nmeasure, "stackBestOff out of range");
    727774
    728     secfilt[Nsec].Nstack    = Nstack;
     775    // record the selected primary measurement
     776    secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset;
     777    myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range");
     778
     779    // this is the selected measurement used by secfilt[]
     780    measure[meas].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
     781    if (Nprimary) {
     782      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;
     783      if (Nprimary > 1) {
     784        secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY_MULTIPLE;
     785      }
     786    }
     787
     788    // stack measurement used for 'best' was a detection (not forced from the other bands)
     789    if ((measure[bestEntryMax].photFlags2 & 0x00000004) == 0) {
     790      secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET;
     791    }
     792
     793    // stack measurement used for 'primary' was a detection (not forced from the other bands)
     794    if ((primaryEntryMax >= 0) && ((measure[primaryEntryMax].photFlags2 & 0x00000004) == 0)) {
     795      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET;
     796    }
     797
     798    secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK;
     799
     800    // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
     801    // float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF);
     802   
     803    // data quality assessment
     804    isBad |= (measure[meas].photFlags & photcodes[Ns][0].photomBadMask);
     805    isBad |= (measure[meas].psfQF < 0.85);
     806    isBad |= isnan(measure[meas].psfQF);
     807    isBad |= measure[meas].dM > 0.2; // S/N < 5.0
     808
     809    isSuspect |= (measure[meas].photFlags & photcodes[Ns][0].photomPoorMask);
     810    isSuspect |= (measure[meas].psfQFperf < 0.85);
     811
     812    if (!isSuspect && !isBad) {
     813      NstackGood ++;
     814    }
     815    if (isSuspect && !isBad) {
     816      NstackSuspect ++;
     817    }
     818
     819    secfilt[Nsec].Nstack    = NstackMeas;
    729820    secfilt[Nsec].NstackDet = NstackDet;
    730821
    731     // this is the measurement used by secfilt[]
    732     measure[k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
    733     if (k == stackPrimaryMeasure) {
    734       secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;
    735     }
    736 
    737     // stack measurement used for 'best' was a detection (not forced from the other bands)
    738     if ((measure[k].photFlags2 & 0x00000004) == 0) {
    739       secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET;
    740     }
    741     // stack measurement used for 'primary' was a detection (not forced from the other bands)
    742     if ((stackPrimaryMeasure >= 0) && ((measure[stackPrimaryMeasure].photFlags2 & 0x00000004) == 0)) {
    743       secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET;
    744     }
    745 
    746     secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK;
    747822  } // Nsecfilt loop
    748823
     
    755830
    756831  int PrimaryIsBest = TRUE;
    757   for (Ns = 0; Ns < Nphotcodes; Ns++) {
     832  for (int Ns = 0; Ns < Nphotcodes; Ns++) {
    758833    if (!(secfilt[Ns].flags & ID_SECF_HAS_PS1_STACK)) continue; // no stack detection in PS1, nothing is best
    759834    if (secfilt[Ns].flags & ID_SECF_STACK_PRIMARY) continue;    // primary stack detection is best
     
    780855// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
    781856// analysis is done on flux, not mags (as the faintest objects will be nearly insignificant)
     857
     858// Although I calculate McalAPER for exposures, I am only using McalPSF for warps..
     859// Note in StarOps.c:setMcalOutput I am setting measure->McalAPER to image->McalPSF for
     860// chips and warps, but not stacks
     861
    782862int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
    783863  OHANA_UNUSED_PARAM(flatcorr);
     
    857937      // data for which the associated image has not been loaded (probably because of
    858938      // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
    859       Mcal = measure[k].Mcal; // check that this is zero for loaded REF value
     939      Mcal = measure[k].McalPSF; // check that this is zero for loaded REF value
    860940    } else {
    861       // use getMcal not getMcal_alt?
    862       Mcal  = getMcal_alt (meas, cat, NULL, measure[k].Xccd, measure[k].Yccd);
    863       // Mcal  = getMcal (meas, cat);
     941      Mcal  = getMcal (meas, cat, MAG_CLASS_PSF);
    864942      if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
    865943    }
  • trunk/Ohana/src/relphot/src/setMrelFinal.c

    r39632 r40291  
    6565          if (catalog[0].measure[m].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
    6666            if (!KEEP_UBERCAL) {
    67               catalog[0].measure[m].Mcal = 0.0;
     67              catalog[0].measure[m].McalPSF  = 0.0;
     68              catalog[0].measure[m].McalAPER = 0.0;
    6869              catalog[0].measure[m].dbFlags &= ~ID_MEAS_PHOTOM_UBERCAL;
    6970            }
    7071          } else {
    7172            if (RESET_ZEROPTS && (getImageEntry (m, 0) >= 0)) {
    72               catalog[0].measure[m].Mcal = 0.0;
     73              catalog[0].measure[m].McalPSF  = 0.0;
     74              catalog[0].measure[m].McalAPER = 0.0;
    7375            }
    7476          }
     
    105107  ALLOCATE (catalog[0].measureRank, char, catalog[0].Nmeasure);
    106108  setMeasureRank (catalog);
    107   setMrelOutput (catalog, 1, flatcorr); // sets the values secfilt.M = <measure.M + measure.Mflat - image.Mcal>
     109  setMrelOutput (catalog, 1, flatcorr); // sets the values secfilt.MpsfChp = <measure.M + measure.Mflat - image.Mcal>
    108110  setMcalOutput (catalog, 1, flatcorr); // sets measure.Mcal = image.Mcal
    109111
     
    226228        off_t Nim = getImageEntry (m, 0);
    227229        if (Nim > -1) {
    228           if (isnan(getMcal (m, 0, flatcorr, catalog))) goto skip;
     230          if (isnan(getMcal (m, 0, MAG_CLASS_PSF))) goto skip;
    229231          if (isnan(getMmos (m, 0))) goto skip;
    230232        }
  • trunk/Ohana/src/relphot/src/share_image_mags.c

    r36630 r40291  
    7474      continue;
    7575    }
    76     images[seq].Mcal        = image_mags[i].Mcal;
     76    images[seq].McalPSF     = image_mags[i].McalPSF;
     77    images[seq].McalAPER    = image_mags[i].McalAPER;
    7778    images[seq].dMcal       = image_mags[i].dMcal;
    7879    images[seq].dMagSys     = image_mags[i].dMagSys;
    79     images[seq].Xm          = image_mags[i].Xm;
     80    images[seq].McalChiSq   = image_mags[i].McalChiSq;
    8081    images[seq].nFitPhotom  = image_mags[i].nFitPhotom;
    8182    images[seq].flags       = image_mags[i].flags;
     
    9192int set_image_mags (ImageMag *image_mags, Image *image) {
    9293
    93   image_mags->Mcal        = image->Mcal;
     94  image_mags->McalPSF     = image->McalPSF;
     95  image_mags->McalAPER    = image->McalAPER;
    9496  image_mags->dMcal       = image->dMcal;
    9597  image_mags->dMagSys     = image->dMagSys;
    96   image_mags->Xm          = image->Xm;
     98  image_mags->McalChiSq   = image->McalChiSq;
    9799  image_mags->nFitPhotom  = image->nFitPhotom;
    98100  image_mags->flags       = image->flags;
  • trunk/Ohana/src/relphot/src/share_mean_mags.c

    r39457 r40291  
    111111    if (Nsec < 0) continue;
    112112
    113     catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].M = meanmags[i].M;
     113    catalog[catSeq].secfilt[objSeq*Nsecfilt + Nsec].MpsfChp = meanmags[i].M;
    114114  }
    115115  free (meanmags);
     
    122122int set_mean_mags (MeanMag *meanmags, AverageTiny *average, SecFilt *secfilt, int Nsec) {
    123123
    124   meanmags->M  = secfilt->M;
    125   meanmags->dM = secfilt->dM;
     124  meanmags->M  = secfilt->MpsfChp;
     125  meanmags->dM = secfilt->dMpsfChp;
    126126  meanmags->Mchisq = secfilt->Mchisq;
    127127  meanmags->Nsec = Nsec; // key to secfilt entry
  • trunk/Ohana/src/relphot/src/synthetic_mags.c

    r39457 r40291  
    3737  // (r - i > 0.5) : w = r + 0.268 - 0.435 (r-i) - 0.078(r-i)^2
    3838
    39   float Mr = secfilt[NSr].M;
    40   float Mi = secfilt[NSi].M;
     39  float Mr = secfilt[NSr].MpsfChp;
     40  float Mi = secfilt[NSi].MpsfChp;
    4141
    4242  if (!isfinite(Mr)) return FALSE;
  • trunk/Ohana/src/uniphot/include/setphot.h

    r39926 r40291  
    1111
    1212typedef struct {
    13   float Mcal;
     13  float McalPSF;
     14  float McalAPER;
    1415  float dMcal;
    1516  unsigned int imageID;
  • trunk/Ohana/src/uniphot/src/ImageSubset.c

    r37043 r40291  
    5656  char type[16];
    5757
    58   GET_COLUMN (Mcal,    "MCAL",       float);
    59   GET_COLUMN (dMcal,   "MCAL_ERR",   float);
    60   GET_COLUMN (imageID, "IMAGE_ID",   int);
    61   GET_COLUMN (map,     "PHOTOM_MAP", int);
    62   GET_COLUMN (flags,   "FLAGS",      int);
     58  GET_COLUMN (McalPSF,  "MCAL_PSF",   float);
     59  GET_COLUMN (McalAPER, "MCAL_APER",  float);
     60  GET_COLUMN (dMcal,    "MCAL_ERR",   float);
     61  GET_COLUMN (imageID,  "IMAGE_ID",   int);
     62  GET_COLUMN (map,      "PHOTOM_MAP", int);
     63  GET_COLUMN (flags,    "FLAGS",      int);
    6364
    6465  // XXX free the fits table data here
     
    6970    image[i].photom_map_id = map[i];
    7071    image[i].flags         = flags[i];
    71     image[i].Mcal          = Mcal[i];
     72    image[i].McalPSF       = McalPSF[i];
     73    image[i].McalAPER      = McalAPER[i];
    7274    image[i].dMcal         = dMcal[i];
    7375  }
    7476  fprintf (stderr, "loaded data for %lld images\n", (long long) Nrow);
    7577
    76   free (Mcal);
     78  free (McalPSF);
     79  free (McalAPER);
    7780  free (dMcal);
    7881  free (imageID);
     
    108111  gfits_create_table (&theader, &ftable);
    109112
    110   float *Mcal, *dMcal;
    111   unsigned int *imageID, *map, *flags;
    112 
    113113  // create intermediate storage arrays
    114   ALLOCATE (Mcal,    float,        Nimage);
    115   ALLOCATE (dMcal,   float,        Nimage);
    116   ALLOCATE (imageID, unsigned int, Nimage);
    117   ALLOCATE (map,     unsigned int, Nimage);
    118   ALLOCATE (flags,   unsigned int, Nimage);
     114  ALLOCATE_PTR (McalPSF,  float,        Nimage);
     115  ALLOCATE_PTR (McalAPER, float,        Nimage);
     116  ALLOCATE_PTR (dMcal,    float,        Nimage);
     117  ALLOCATE_PTR (imageID,  unsigned int, Nimage);
     118  ALLOCATE_PTR (map,      unsigned int, Nimage);
     119  ALLOCATE_PTR (flags,    unsigned int, Nimage);
    119120
    120121  // assign the storage arrays
    121122  for (i = 0; i < Nimage; i++) {
    122     imageID[i] = image[i].imageID;
    123     map[i]     = image[i].photom_map_id;
    124     flags[i]   = image[i].flags;
    125     Mcal[i]    = image[i].Mcal;
    126     dMcal[i]   = image[i].dMcal;
     123    imageID[i]  =  image[i].imageID;
     124    map[i]      =  image[i].photom_map_id;
     125    flags[i]    =  image[i].flags;
     126    McalPSF[i]  =  image[i].McalPSF;
     127    McalAPER[i] =  image[i].McalAPER;
     128    dMcal[i]    =  image[i].dMcal;
    127129  }
    128130
    129131  // add the columns to the output array
    130   gfits_set_bintable_column (&theader, &ftable, "MCAL",       Mcal,    Nimage);
    131   gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",   dMcal,   Nimage);
    132   gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",   imageID, Nimage);
    133   gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP", map,     Nimage);
    134   gfits_set_bintable_column (&theader, &ftable, "FLAGS",      flags,   Nimage);
     132  gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",   McalPSF,  Nimage);
     133  gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER, Nimage);
     134  gfits_set_bintable_column (&theader, &ftable, "MCAL_ERR",   dMcal,    Nimage);
     135  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",   imageID,  Nimage);
     136  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP", map,      Nimage);
     137  gfits_set_bintable_column (&theader, &ftable, "FLAGS",      flags,    Nimage);
    135138
    136   free (Mcal);
     139  free (McalPSF);
     140  free (McalAPER);
    137141  free (dMcal);
    138142  free (imageID);
     
    174178    image[i].photom_map_id = subset[i].photom_map_id;
    175179    image[i].flags         = subset[i].flags        ;
    176     image[i].Mcal          = subset[i].Mcal         ;
     180    image[i].McalPSF       = subset[i].McalPSF      ;
     181    image[i].McalAPER      = subset[i].McalAPER     ;
    177182    image[i].dMcal         = subset[i].dMcal        ;
    178183  }
  • trunk/Ohana/src/uniphot/src/dumpresult.c

    r31160 r40291  
    22
    33void dumpresult () {
    4   short Mcal, Mgrp, Mset;
     4  float Mcal, Mgrp, Mset;
    55  FILE *f;
    66  char outfile[64];
     
    1313      if (sgroup[i].image[j][0].code & IMAGE_BAD) continue;
    1414      tgrp = (Group *) sgroup[i].imlink[j][0].tgroup;
    15       Mcal = sgroup[i].image[j][0].Mcal;
     15      Mcal = sgroup[i].image[j][0].McalPSF;
    1616      Mset = sgroup[i].M;
    1717      Mgrp = tgrp[0].M;
  • trunk/Ohana/src/uniphot/src/fit_groups.c

    r31160 r40291  
    1818      if (tgroup[i].image[j][0].flags & IMAGE_BAD) continue;
    1919      sgroup = (Group *) tgroup[i].imlink[j][0].sgroup;
    20       Mcal = tgroup[i].image[j][0].Mcal;
     20      Mcal = tgroup[i].image[j][0].McalPSF;
    2121      Mgrp = sgroup[0].M;
    2222      mlist[Nlist] = (Mcal - Mgrp);
     
    5858      if (sgroup[i].image[j][0].flags & IMAGE_BAD) continue;
    5959      tgroup = (Group *) sgroup[i].imlink[j][0].tgroup;
    60       Mcal = sgroup[i].image[j][0].Mcal;
     60      Mcal = sgroup[i].image[j][0].McalPSF;
    6161      Mgrp = tgroup[0].M;
    6262      mlist[Nlist] = (Mcal - Mgrp);
  • trunk/Ohana/src/uniphot/src/match_zpts_to_images.c

    r37807 r40291  
    4141  if (RESET) {
    4242    for (i = 0; i < Nimage; i++) {
    43       image[i].Mcal = 0.0;
    44       image[i].dMcal = NAN;
    45       image[i].flags &= ~ID_IMAGE_PHOTOM_NOCAL; // clear the NOCAL flag
     43      image[i].McalPSF  = 0.0;
     44      image[i].McalAPER = 0.0;
     45      image[i].dMcal    = NAN;
     46      image[i].flags   &= ~ID_IMAGE_PHOTOM_NOCAL; // clear the NOCAL flag
    4647      if (UBERCAL) {
    4748        image[i].flags &= ~ID_IMAGE_PHOTOM_UBERCAL; // clear the UBERCAL flag
     
    107108    // UBERCAL includes 2.5log(exptime) + K*airmass in the zero point
    108109    if (UBERCAL) {
    109       image[Ni].Mcal = SCALE*code[0].C - zpts[Nz].zpt + 2.5*log10(image[Ni].exptime) + code[0].K*(image[Ni].secz - 1.000);
    110       myAssert (isfinite(image[Ni].Mcal), "oops, ubercal made a nan image");
     110      image[Ni].McalPSF  = SCALE*code[0].C - zpts[Nz].zpt + 2.5*log10(image[Ni].exptime) + code[0].K*(image[Ni].secz - 1.000);
     111      image[Ni].McalAPER = SCALE*code[0].C - zpts[Nz].zpt + 2.5*log10(image[Ni].exptime) + code[0].K*(image[Ni].secz - 1.000);
     112      myAssert (isfinite(image[Ni].McalPSF), "oops, ubercal made a nan image");
    111113    } else {
    112       image[Ni].Mcal = SCALE*code[0].C - zpts[Nz].zpt;
     114      image[Ni].McalPSF  = SCALE*code[0].C - zpts[Nz].zpt;
     115      image[Ni].McalAPER = SCALE*code[0].C - zpts[Nz].zpt;
    113116    }
    114117
     
    116119    float offset = apply_zpt_offset (code[0].equiv);
    117120    assert (isfinite(offset));
    118     image[Ni].Mcal += offset;
     121    image[Ni].McalPSF  += offset;
     122    image[Ni].McalAPER += offset;
    119123
    120124    image[Ni].dMcal = zpts[Nz].zpt_err;
  • trunk/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r39288 r40291  
    153153        case 101:
    154154        case 102: {
    155           float gmag = secfilt[Nsec_g].M;
    156           float imag = secfilt[Nsec_i].M;
     155          float gmag = secfilt[Nsec_g].MpsfChp;
     156          float imag = secfilt[Nsec_i].MpsfChp;
    157157          dColor = average->refColorBlue - (gmag - imag);
    158158          break;
     
    160160        case 103:
    161161        case 104: {
    162           float zmag = secfilt[Nsec_z].M;
    163           float ymag = secfilt[Nsec_y].M;
     162          float zmag = secfilt[Nsec_z].MpsfChp;
     163          float ymag = secfilt[Nsec_y].MpsfChp;
    164164          dColor = average->refColorRed - (zmag - ymag);
    165165          break;
  • trunk/Ohana/src/uniphot/src/update_catalog_setphot.c

    r39926 r40291  
    3939    if (id < 0) continue;
    4040
    41     float Mcal = image[id].Mcal;
     41    float Mcal  = image[id].McalPSF;
    4242    float dMcal = image[id].dMcal;
    4343    float Mflat = 0.0;
     
    6161# endif
    6262
    63     measure[0].Mcal = Mcal;
     63    myAssert(isfinite(Mcal), "oops: ubercal made a nan");
     64
     65    measure[0].McalPSF  = Mcal;
     66    measure[0].McalAPER = Mcal;
    6467    measure[0].Mflat = Mflat; // in the previous version, Mcal_offset (which is added to Mflat) had a negative sign here
    6568    measure[0].dMcal = dMcal;
    66     myAssert(isfinite(measure[0].Mcal), "oops: ubercal made a nan");
    6769
    6870    if (RESET) {
  • trunk/Ohana/src/uniphot/src/update_catalog_uniphot.c

    r33654 r40291  
    1414  for (i = 0; i < catalog[0].Naverage; i++) {
    1515   
    16     if (!isnan(catalog[0].secfilt[i*Nsecfilt+Nsec].M)) {
    17       catalog[0].secfilt[i*Nsecfilt+Nsec].M += sgroup[0].M;
     16    if (!isnan(catalog[0].secfilt[i*Nsecfilt+Nsec].MpsfChp)) {
     17      catalog[0].secfilt[i*Nsecfilt+Nsec].MpsfChp += sgroup[0].M;
    1818    }
    1919
     
    2424      if (code[0].type != PHOT_DEP) continue;
    2525      if (code[0].equiv != photcode[0].code) continue;
    26       catalog[0].measure[m].Mcal -= sgroup[0].M;
     26      catalog[0].measure[m].McalPSF  -= sgroup[0].M;
     27      catalog[0].measure[m].McalAPER -= sgroup[0].M;
    2728      found ++;
    2829    }
  • trunk/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r38986 r40291  
    3737  for (i = 0; i < Nsgroup; i++) {
    3838    for (j = 0; j < sgroup[i].Nimage; j++) {
    39       sgroup[i].image[j][0].Mcal -= sgroup[i].M;
     39      sgroup[i].image[j][0].McalPSF  -= sgroup[i].M;
     40      sgroup[i].image[j][0].McalAPER -= sgroup[i].M;
    4041    }
    4142  }
Note: See TracChangeset for help on using the changeset viewer.