IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40477


Ignore:
Timestamp:
Jun 27, 2018, 3:20:35 PM (8 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/czw_branch/20170908/Ohana
Files:
1 deleted
250 edited
35 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20170908/Ohana

  • branches/czw_branch/20170908/Ohana/Makefile.in

    r40019 r40477  
    5151relphot     \
    5252relastro    \
     53skycalc     \
    5354shell       \
    5455tools       \
     
    6162fixcat      \
    6263gophot      \
    63 skycalc     \
    6464getusno     \
    6565lightcurve  \
  • branches/czw_branch/20170908/Ohana/src/addstar/src/FilterStars.c

    r39473 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/LoadDataPMM.c

    r38553 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/ReadImageHeader.c

    r39457 r40477  
    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 */
  • branches/czw_branch/20170908/Ohana/src/addstar/src/ReadSDSSHeader.c

    r16810 r40477  
    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));
  • branches/czw_branch/20170908/Ohana/src/addstar/src/ReadStarsSDSS.c

    r39161 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/ReadStarsUKIRT.c

    r39161 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/SEDfit.c

    r38467 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/calibrate.c

    r39457 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/addstar/src/fakeimage.c

    r37807 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/addstar/src/find_matches.c

    r38986 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/addstar/src/find_matches_closest.c

    r38986 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/addstar/src/find_matches_gaia.c

    r39926 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/addstar/src/find_proper.c

    r15036 r40477  
    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 */
  • branches/czw_branch/20170908/Ohana/src/addstar/src/loadgalphot_readstars.c

    r39542 r40477  
    241241
    242242    int ifit = idx_gal[i];
    243     if (ifit < 0) { Nbad ++; continue; } // skip galaxy models with bad IDs
     243    if (ifit < 0) {
     244      fprintf (stderr, "%d %f %f %d\n", i, X_FIT[i], Y_FIT[i], MODEL_TYPE_gal[i]);
     245      Nbad ++;
     246      continue;
     247    } // skip galaxy models with bad IDs
    244248
    245249    double R, D;
  • branches/czw_branch/20170908/Ohana/src/addstar/src/loadsupercos_plates.c

    r37807 r40477  
    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];
  • branches/czw_branch/20170908/Ohana/src/addstar/src/loadsupercos_rawdata.c

    r39457 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/addstar/src/mkcmf.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/checkastro/src/BrightCatalog.c

    r37043 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/delstar/Makefile

    r39692 r40477  
    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 \
  • branches/czw_branch/20170908/Ohana/src/delstar/include/delstar.h

    r39926 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/delstar/src/args.c

    r39926 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/delstar/src/delstar.c

    r39692 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/delstar/src/delstar_client.c

    r39692 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/delstar/src/gimages.c

    r39457 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/dvolens/src/update_objects_catalog.c

    r39611 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/dvomerge/include/dvomerge.h

    r39926 r40477  
    5555int    MATCH_BY_EXTERN_ID;
    5656
     57int    ONLY_MATCHES;
     58
    5759int    MATCHED_TABLES;
    5860int    RESET_STARPAR;
  • branches/czw_branch/20170908/Ohana/src/dvomerge/src/args.c

    r39926 r40477  
    8686  }
    8787
    88   /* extra error messages */
     88  /* match images in the src and tgt database tables by their externID values (otherwise by time and photcode) */
    8989  MATCH_BY_EXTERN_ID = FALSE;
    9090  if ((N = get_argument (*argc, argv, "-match-by-extern-id"))) {
    9191    MATCH_BY_EXTERN_ID = TRUE;
     92    remove_argument (N, argc, argv);
     93  }
     94  /* add objects from input to output database only if they match an existing object */
     95  ONLY_MATCHES = FALSE;
     96  if ((N = get_argument (*argc, argv, "-only-matches"))) {
     97    ONLY_MATCHES = TRUE;
    9298    remove_argument (N, argc, argv);
    9399  }
     
    373379  }
    374380
    375   /* extra error messages */
     381  /* match images in the src and tgt database tables by their externID values (otherwise by time and photcode) */
    376382  MATCH_BY_EXTERN_ID = FALSE;
    377383  if ((N = get_argument (*argc, argv, "-match-by-extern-id"))) {
    378384    MATCH_BY_EXTERN_ID = TRUE;
     385    remove_argument (N, argc, argv);
     386  }
     387  /* add objects from input to output database only if they match an existing object */
     388  ONLY_MATCHES = FALSE;
     389  if ((N = get_argument (*argc, argv, "-only-matches"))) {
     390    ONLY_MATCHES = TRUE;
    379391    remove_argument (N, argc, argv);
    380392  }
  • branches/czw_branch/20170908/Ohana/src/dvomerge/src/build_links.c

    r40127 r40477  
    701701  off_t *next_galphot;
    702702
    703   if (galphot) return NULL;
     703  if (!galphot) return NULL;
    704704  if (SKIP_GALPHOT) return NULL;
    705705
  • branches/czw_branch/20170908/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r39926 r40477  
    330330    if (MATCHED_TABLES)      { strextend (&command, "-matched-tables"); }
    331331    if (MATCH_BY_EXTERN_ID)  { strextend (&command, "-match-by-extern-id"); }
     332    if (ONLY_MATCHES)        { strextend (&command, "-only-matches"); }
    332333    if (UPDATE_CATFORMAT)    { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
    333334    if (UPDATE_CATCOMPRESS)  { strextend (&command, "-update-catcompress %s", UPDATE_CATCOMPRESS); }
  • branches/czw_branch/20170908/Ohana/src/dvomerge/src/dvosecfilt_catalogs.c

    r38986 r40477  
    4141    // always load all of the data (if any exists)
    4242    catalog.Nsecfilt  = 0;
    43     catalog.catflags  = DVO_LOAD_SECFILT;  // XXX this will fail for MEF version
     43    catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;  // XXX this will fail for MEF version
    4444    catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
    4545    catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
  • branches/czw_branch/20170908/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r39926 r40477  
    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      }
     
    406406  /** incorporate unmatched image stars, if this star is in field of this catalog **/
    407407  /* these new entries are all written out in UPDATE mode */
    408   for (i = 0; i < Nstars; i++) {
     408  for (i = 0; (i < Nstars) && !ONLY_MATCHES; i++) {
    409409    off_t N = N1[i];
    410410
     
    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      }
  • branches/czw_branch/20170908/Ohana/src/dvopsps/include/dvopsps.h

    r39112 r40477  
    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;
     
    3436  unsigned int flags;
    3537  unsigned int objflags;
     38  unsigned int filtflags;
    3639} Detections;
    3740
     
    4548
    4649int          SAVE_REMOTE;
     50int          TEST_MODE;
    4751
    4852int          PARALLEL;
     
    96100int    insert_detections_mysql_array      PROTO((MYSQL *mysql, Detections *detections, int Ndetections));
    97101int    insert_detections_mysql_detvalue   PROTO((IOBuffer *buffer, Detections *detection));
    98 int    assign_detection_values            PROTO((Detections *detection, Measure *measure, Average *average));
     102int    assign_detection_values            PROTO((Detections *detection, Measure *measure, Average *average, SecFilt *secfilt));
    99103
    100104int    init_detections                    PROTO((void));
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/DetectionOps.c

    r39547 r40477  
    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     );
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/initialize_dvopsps.c

    r38674 r40477  
    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"))) {
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps.c

    r38471 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/insert_FWobjects_dvopsps_catalog.c

    r39593 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r39645 r40477  
    1919
    2020  ZeroPoint = GetZeroPoint();
     21  int Nsecfilt = GetPhotcodeNsecfilt ();
    2122
    2223  int missingID = 0;
     
    5152      if (measure->photcode >=  PHOTCODE_END) continue;
    5253
    53       assign_detection_values (&detections[Ndetections], measure, average);
     54      int equivCode = GetPhotcodeEquivCodebyCode (measure->photcode);
     55      int Nsec = GetPhotcodeNsec (equivCode);
     56
     57      SecFilt *secfilt = (Nsec >= 0) ? &catalog->secfilt[Nsecfilt*i + Nsec] : NULL;
     58
     59      assign_detection_values (&detections[Ndetections], measure, average, secfilt);
    5460      Ndetections ++;
    5561
     
    97103
    98104  ZeroPoint = GetZeroPoint();
     105  int Nsecfilt = GetPhotcodeNsecfilt ();
    99106
    100107  INITTIME;
     
    127134      if (measure[Nmeas].photcode >=  PHOTCODE_END) continue;
    128135
     136      int equivCode = GetPhotcodeEquivCodebyCode (measure[Nmeas].photcode);
     137      int Nsec = GetPhotcodeNsec (equivCode);
     138
     139      SecFilt *secfilt = (Nsec > -1) ? &catalog->secfilt[Nsecfilt*i + Nsec] : NULL;
     140
    129141      // XXX check return status
    130142      Detections detection;
    131       assign_detection_values (&detection, &measure[Nmeas], &average[i]);
     143      assign_detection_values (&detection, &measure[Nmeas], &average[i], secfilt);
    132144
    133145      if (!insert_detections_mysql_detvalue (&buffer, &detection)) {
     
    183195
    184196  PrintIOBuffer (buffer, "INSERT INTO dvoDetectionFull (objID, detectID, ippObjID, ippDetectID, imageID, catID, ");
    185   PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zp, zpFactor, telluricExt, airmass, expTime, ");
    186   PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags, objflags) VALUES \n");
     197  PrintIOBuffer (buffer, "ra, dec_, raErr, decErr, zpPSF, zpFactorPSF, zpAPER, zpFactorAPER, telluricExt, airmass, expTime, ");
     198  PrintIOBuffer (buffer, "Mpsf, dMpsf, Mkron, dMkron, Map, dMap, flags, objflags, filtflags) VALUES \n");
    187199
    188200  return TRUE;
     
    254266  PRINT_FLOAT(buffer, detection->raErr,       "%.6f, ");
    255267  PRINT_FLOAT(buffer, detection->decErr,      "%.6f, ");
    256   PRINT_FLOAT(buffer, detection->zp,          "%.6f, ");
    257   PRINT_FLOAT(buffer, detection->zpFactor,    "%.6e, ");
     268  PRINT_FLOAT(buffer, detection->zpPSF,       "%.6f, ");
     269  PRINT_FLOAT(buffer, detection->zpFactorPSF, "%.6e, ");
     270  PRINT_FLOAT(buffer, detection->zpAPER,      "%.6f, ");
     271  PRINT_FLOAT(buffer, detection->zpFactorAPER,"%.6e, ");
    258272  PRINT_FLOAT(buffer, detection->telluricExt, "%.6f, ");
    259273  PRINT_FLOAT(buffer, detection->airmass,     "%.6f, ");
     
    268282
    269283  PrintIOBuffer (buffer, "%u, ", detection->flags);      // measure.flags
    270   PrintIOBuffer (buffer, "%u),\n", detection->objflags); // average.flags
     284  PrintIOBuffer (buffer, "%u, ", detection->objflags); // average.flags
     285  PrintIOBuffer (buffer, "%u),\n", detection->filtflags); // secfilt.flags
    271286  return TRUE;
    272287}
     
    303318}
    304319
    305 int assign_detection_values (Detections *detection, Measure *measure, Average *average) {
     320int assign_detection_values (Detections *detection, Measure *measure, Average *average, SecFilt *secfilt) {
     321
     322  // myAbort ("check on measure->McalPSF vs McalAPER");
    306323
    307324  PhotCode *code = GetPhotcodebyCode(measure->photcode);
     
    311328  float Mflat       = isfinite(measure->Mflat) ? measure->Mflat : 0.0;
    312329  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;
     330  float zpPSF       = nominalZP - measure->McalPSF - Mflat;
     331  float zpFactorPSF = pow(10.0, -0.4*zpPSF + 3.56);
     332  float zpAPER      = nominalZP - measure->McalAPER - Mflat;
     333  float zpFactorAPER= pow(10.0, -0.4*zpAPER + 3.56);
     334  float telluricExt = - measure->McalPSF;
    316335  float expTime     = pow(10.0, 0.4 * measure->dt);
    317336  float airmass     = measure->airmass;
     
    329348  detection->decErr       = measure->dYccd * 0.01 * fabs(measure->pltscale); // estimate of decErr
    330349
    331   detection->zp           = zp;
    332   detection->zpFactor     = zpFactor;
     350  detection->zpPSF        = zpPSF;
     351  detection->zpFactorPSF  = zpFactorPSF;
     352  detection->zpAPER       = zpAPER;
     353  detection->zpFactorAPER = zpFactorAPER;
    333354  detection->telluricExt  = telluricExt;
    334355  detection->airmass      = airmass;
     
    337358  // XXX clean this up with dvo_photcode_ops calls:
    338359  // 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);
     360  detection->Mpsf  = getMagFromValueOrFlux (measure->FluxPSF,  measure->M,     zpPSF);
     361  detection->Mkron = getMagFromValueOrFlux (measure->FluxKron, measure->Mkron, zpAPER);
     362  detection->Map   = getMagFromValueOrFlux (measure->FluxAp,   measure->Map,   zpAPER);
    342363
    343364  detection->dMpsf  = getdMagFromValueOrFlux (measure->FluxPSF,  measure->dFluxPSF,  measure->dM);
     
    347368  detection->flags     = measure->dbFlags; // flags
    348369  detection->objflags  = average->flags;   // flags
    349 
    350   return TRUE;
    351 }
    352 
     370  detection->filtflags = secfilt ? secfilt->flags : 0; // flags
     371
     372  return TRUE;
     373}
     374
  • branches/czw_branch/20170908/Ohana/src/dvopsps/src/insert_objects_dvopsps_catalog.c

    r39650 r40477  
    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}
  • branches/czw_branch/20170908/Ohana/src/fakeastro/src/insert_fakestar.c

    r38469 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/fakeastro/src/load_template_images.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/fakeastro/src/make_2mass_measures.c

    r39248 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/fakeastro/src/make_fake_stars_catalog.c

    r39926 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/fakeastro/src/make_gaia_measures.c

    r39926 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/getstar/src/ReadImageHeader.c

    r39998 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/getstar/src/select_by_region.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/imregister/imphot/dumpfits.c

    r38441 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/imregister/imphot/output.c

    r34088 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/kapa2/include/constants.h

    r39225 r40477  
    2727# define MIN_WIDTH 50
    2828# define MIN_HEIGHT 50
    29 # define LABEL_MAXLEN 128
     29# define LABEL_MAXLEN 512
    3030
    3131typedef enum {
  • branches/czw_branch/20170908/Ohana/src/kapa2/include/prototypes.h

    r39926 r40477  
    3636int           DrawObjectN         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
    3737void          DrawPoints          PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     38void          DrawBars            PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode));
    3839void          ClipLine            PROTO((Graphic *graphic, double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1));
    3940void          DrawXErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     
    139140void          bDrawConnect        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
    140141void          bDrawHistogram      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
     142void          bDrawBars           PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode));
    141143void          bDrawPoints         PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
    142144void          bDrawXErrors        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
  • branches/czw_branch/20170908/Ohana/src/kapa2/include/structures.h

    r39457 r40477  
    115115typedef struct {
    116116  int x, y;
    117   int dx, dy;
     117  int dx, dy; // unused?
    118118  double angle;
    119119  int  size;
     120  int justify;
     121  int color;
    120122  char font[64];
    121123  char text[LABEL_MAXLEN];
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/DrawObjects.c

    r40116 r40477  
    11# include "Ximage.h"
    22
    3 void DrawBars (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode);
     3/* DrawRectangle & FillRectangle : take rectangle lower-left corner and widths
     4   DrawCircle & FillCircle : take circle center and radius
     5*/
    46
    57# define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
    6 # define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
    7 # define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
    8 // # define FillRectangle(X1,Y1,X2,Y2) ;
     8# define DrawRectangle(X,Y,dX,dY) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(dX), (int)(dY)))
     9# define FillRectangle(X,Y,dX,dY) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(dX), (int)(dY)))
    910# define DrawCircle(X,Y,R) (XDrawArc (graphic->display, graphic->window, graphic->gc, (int)(X-R), (int)(Y-R), abs(2*R), abs(2*R), 0, 23040))
    1011# define FillCircle(X,Y,R) (XFillArc (graphic->display, graphic->window, graphic->gc, (int)(X-R), (int)(Y-R), abs(2*R), abs(2*R), 0, 23040))
     
    9697  switch (object[0].style) {
    9798    case KAPA_PLOT_CONNECT:
     99      // fprintf (stderr, "plot KAPA_PLOT_CONNECT: \n");
    98100      DrawConnect (graphic, graph, object);
    99101      break;
    100102    case KAPA_PLOT_HISTOGRAM:
     103      // fprintf (stderr, "plot KAPA_PLOT_HISTOGRAM:\n");
    101104      DrawHistogram (graphic, graph, object);
    102105      break;
    103106    case KAPA_PLOT_BARS_SOLID:
     107      // fprintf (stderr, "plot KAPA_PLOT_BARS_SOLID:\n");
    104108      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_SOLID);
    105109      break;
    106110    case KAPA_PLOT_BARS_OUTLINE:
     111      // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTLINE:\n");
    107112      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTLINE);
    108113      break;
    109114    case KAPA_PLOT_BARS_OUTFILL:
     115      // fprintf (stderr, "plot KAPA_PLOT_BARS_OUTFILL:\n");
    110116      DrawBars (graphic, graph, object, KAPA_PLOT_BARS_OUTFILL);
    111117      break;
    112118    case KAPA_PLOT_POINTS:
    113119    default:
     120      // fprintf (stderr, "plot KAPA_PLOT_POINTS:\n");
    114121      DrawPoints (graphic, graph, object);
    115122      break;
     
    162169    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    163170    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    164    
    165171    ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    166     /* DrawLine (sx0, sy0, sx1, sy1); */
    167172    sx0 = sx1; sy0 = sy1;
    168173  }
     
    225230/******/
    226231/* simplify the code abit by finding triplets, watch out for a histogram of 2 points */
    227 # if (1)
    228232void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    229233
     
    309313  DrawLine (sxa, sy1, sxa, sya);
    310314}
    311 
    312 # else
    313 
    314 void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    315 
    316   int i;
    317   float *x, *y;
    318   double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
    319   double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo;
    320   double X0, X1, Y0, Y1;
    321 
    322   mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);
    323   mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0);
    324   myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0);
    325   myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0);
    326  
    327   bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);
    328   bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);
    329   byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);
    330   byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);
    331  
    332   bx = bxi + bxj;
    333   by = byi + byj;
    334  
    335   X0 = graph[0].axis[0].fx;
    336   X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
    337   Y0 = graph[0].axis[1].fy;
    338   Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
    339 
    340   /* find the first valid datapoint */
    341   x = object[0].x; y = object[0].y;
    342  
    343   /* we only worry about pairs of points of which one is on the screen.  for each such
    344     pair, we draw the connecting lines from sx0,sy0 to sx1,sy1, passing through the point
    345     halfway between. 
    346 
    347     if, for a given point, there was no valid x0,y0, then we call this the first point
    348     save both the current and previous points.
    349   */
    350 
    351   int firstPair = TRUE;
    352   sx0r = sy0r = NAN;
    353   sxPr = syPr = NAN;
    354   for (i = 0; i < object[0].Npts; i++) {
    355     if (!(finite(x[i]) && finite(y[i]))) continue;
    356     sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    357     sy1r = x[i]*myi + y[i]*myj + by + YCENTER;
    358 
    359     // we have hit the first valid point, but not yet the second one
    360     if (!isfinite (sx0r)) {
    361       sx0r = sx1r; sy0r = sy1r;
    362       continue;
    363     }
    364 
    365     if ((sx1r < X0) && (sx0r < X0)) {
    366       // both points to left, skip the pair
    367       sxPr = sx0r; syPr = sy0r;
    368       sx0r = sx1r; sy0r = sy1r;
    369       continue;
    370     }
    371     if ((sx1r > X0) && (sx0r > X0)) {
    372       // both points to right, skip the pair
    373       sxPr = sx0r; syPr = sy0r;
    374       sx0r = sx1r; sy0r = sy1r;
    375       continue;
    376     }
    377 
    378     // saturated values for sx0,sy0
    379     sx0 = MIN (MAX (sx0r, X0), X1);
    380     sy0 = MAX (MIN (sy0r, Y0), Y1);
    381 
    382     // saturated values for sx1,sy1
    383     sx1 = MIN (MAX (sx1r, X0), X1);
    384     sy1 = MAX (MIN (sy1r, Y0), Y1);
    385 
    386     if (firstPair) {
    387       /* draw segment equal distance behind first point and down to x-axis */
    388       sxar = sx0r - 0.5*(sx1r - sx0r);
    389       sxa = MIN (MAX (sxar, X0), X1);
    390       sya = MAX (sy0r, Y0);
    391       XSetForeground (graphic->display, graphic->gc, graphic->fore);
    392       DrawLine (sx0, sy0, sxa, sy0);
    393       DrawLine (sxa, sy0, sxa, sya);
    394       XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]);
    395       FillRectangle (sxa + 3, sy0 + 3, sx0 - sxa - 6, sya - sy0 - 6);
    396       firstPair = FALSE;
    397     }
    398 
    399     // midpoint & saturated version
    400     sxar = 0.5*(sx0r + sx1r);
    401     sxa = MIN (MAX (sxar, X0), X1);
    402 
    403     XSetForeground (graphic->display, graphic->gc, graphic->fore);
    404     DrawLine (sx0, sy0, sxa, sy0);
    405     DrawLine (sxa, sy0, sxa, sy1);
    406     DrawLine (sxa, sy1, sx1, sy1);
    407     XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]);
    408     FillRectangle (sx0 + 3, sy0 + 3, sxa - sx0 - 6, Y0 - sy0 - 6);
    409     FillRectangle (sxa + 3, sy1 + 3, sx1 - sxa - 6, Y0 - sy1 - 6);
    410     sxPr = sx0r; syPr = sy0r;
    411     sx0r = sx1r; sy0r = sy1r;
    412   }
    413  
    414   /* draw segment equal distance after last point and down to x-axis */
    415   sxa = MIN (MAX (sx1 + 0.5*(sx1 - sxo), X0), X1);
    416   sya = MAX (sy1, Y0);
    417   DrawLine (sx1, sy1, sxa, sy1);
    418   DrawLine (sxa, sy1, sxa, sya);
    419 }
    420 # endif
    421315
    422316// uses object->color
     
    498392  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx
    499393     one point at a time
     394
     395     I need to know the distance to the next and prev points to calculate dx
     396     for the first point, dx is x[1] - x[0]
     397     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
     398     for the rest, dx is 0.5*(x[i+1] - x[i-1])
     399   
     400     rather than working out complex on-the-fly logic, I want to find the first and last
     401     valid point in an initial pass, then calculate the above for the remainder.
     402     TBD: make an index vector of only valid points?
    500403  */
    501 
    502   // I need to know the distance to the next and prev points to calculate dx
    503   // for the first point, dx is x[1] - x[0]
    504   // for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
    505   // for the rest, dx is 0.5*(x[i+1] - x[i-1])
    506 
    507   // rather than working out complex on-the-fly logic, I want to find the first and last
    508   // valid point in an initial pass, the calculate the above for the remainder.
    509   // or make an index vector of only valid points?
    510404
    511405  int Ngood = 0;
     
    522416    // coordinate on the screen of the point:
    523417    double sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    524     // double sy1r = x[i]*myi + y[i]*myj + by + YCENTER;
    525418
    526419    if (sx1r < X0) {
     
    576469    n = goodPoint[1];
    577470    double sx1r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
    578 //  double sy1r = x[n]*myi + y[n]*myj + by + YCENTER;
    579471
    580472    n = goodPoint[0];
     
    605497    n = goodPoint[i + 1];
    606498    double sx2r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
    607     // double sy2r = x[n]*myi + y[n]*myj + by + YCENTER;
    608499
    609500    n = goodPoint[i - 1];
    610501    double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
    611     // double sy0r = x[n]*myi + y[n]*myj + by + YCENTER;
    612 
    613     double dx = 0.5*0.5*object->size*(sx2r - sx0r); // 2 factors of 0.5 (we want half of the average spacing)
     502
     503    // below we have 2 factors of 0.5 (we want half of the average spacing)
     504    double dx = 0.5*0.5*object->size*(sx2r - sx0r);
    614505
    615506    n = goodPoint[i];
     
    642533    n = goodPoint[Ngood - 2];
    643534    double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
    644 //  double sy0r = x[n]*myi + y[n]*myj + by + YCENTER;
    645535
    646536    double dx = 0.5*object->size*(sx1r - sx0r);
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/DrawTextlines.c

    r13320 r40477  
    1212  fontname = GetRotFont (&size);
    1313  XSetForeground (graphic->display, graphic->gc, graphic->fore);
    14   DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->fore, graphic->back);
    1514
    1615  for (i = 0; i < graph[0].Ntextline; i++) {
    1716    if (strcmp (graph[0].textline[i].text, "")) {
     17      DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[graph[0].textline[i].color], graphic->back);
    1818      angle = graph[0].textline[i].angle;
    1919      x = graph[0].textline[i].x;
    2020      y = graph[0].textline[i].y;
    2121      SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
    22       DrawRotText (x, y, graph[0].textline[i].text, 5, angle);
     22      DrawRotText (x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
    2323    }
    2424  }
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/LoadObject.c

    r39926 r40477  
    4242      graph[0].objects[N].color = KapaColormapSize() - 1;
    4343  }
    44   if ((graph[0].objects[N].style != 2) && (graph[0].objects[N].color < 0)) {
     44  if ((graph[0].objects[N].style != KAPA_PLOT_POINTS) && (graph[0].objects[N].color < 0)) {
    4545      graph[0].objects[N].color = 0;
    4646  }
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/LoadTextlines.c

    r39626 r40477  
    44 
    55  char *string;
    6   int N, size;
     6  int N, size, justify, color;
    77  double tX, tY, tT, L;
    88  Section *section;
     
    2323  REALLOCATE (graph[0].textline, Label, graph[0].Ntextline);
    2424
    25   KiiScanMessage (sock, "%lf %lf %lf", &tX, &tY, &tT);
     25  KiiScanMessage (sock, "%lf %lf %lf %d %d", &tX, &tY, &tT, &justify, &color);
    2626
    2727  L = graph[0].axis[0].dfx;
     
    5252  graph[0].textline[N].size = size;
    5353  strcpy (graph[0].textline[N].font, string);
     54  graph[0].textline[N].justify = justify;
     55  graph[0].textline[N].color = color;
    5456
    5557  if (USE_XWINDOW) DrawTextlines (graph);
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/PSObjects.c

    r39926 r40477  
    11# include "Ximage.h"
    22
     3void PSBars (KapaGraphWidget *graph, Gobjects *object, FILE *f, int mode);
     4
     5/* DrawRectangle & FillRectangle : take rectangle lower-left corner and widths
     6   DrawCircle & FillCircle : take circle center and radius
     7*/
     8
    39# define DrawLine(X1,Y1,X2,Y2) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f L\n", X1, graphic->dy - Y1, X2, graphic->dy - Y2))
    4 # define DrawRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f B\n", (dX), (dY), (X-0.5*dX), (graphic->dy-Y-0.5*dY)))
    5 # define FillRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f F\n", (dX), (dY), (X-0.5*dX), (graphic->dy-Y-0.5*dY)))
     10# define DrawRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f B\n", (dX), (dY), (X), (graphic->dy-Y)))
     11# define FillRectangle(X,Y,dX,dY) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f F\n", (dX), (dY), (X), (graphic->dy-Y)))
    612# define DrawCircle(X1,Y1,R) (fprintf (f, " %6.2f %6.2f %6.2f C\n", (X1), (graphic->dy - Y1), (R)))
    713# define FillCircle(X1,Y1,R) (fprintf (f, " %6.2f %6.2f %6.2f FC\n", (X1), (graphic->dy - Y1), (R)))
     
    3238}
    3339
    34 int PSObjectsN (KapaGraphWidget *graph, Gobjects *object, FILE *f) {
    35  
     40void PSLineStyle (KapaGraphWidget *graph, Gobjects *object, FILE *f) {
     41
    3642  static char short_dash[] = "4 4";
    3743  static char long_dash[] = "8 8";
     
    6470    fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(object->color));
    6571  }
     72}
     73
     74int PSObjectsN (KapaGraphWidget *graph, Gobjects *object, FILE *f) {
     75 
     76  PSLineStyle (graph, object, f);
    6677
    6778  switch (object->style) {
     
    7182    case KAPA_PLOT_HISTOGRAM:
    7283      PSHistogram (graph, object, f);
     84      break;
     85    case KAPA_PLOT_BARS_SOLID:
     86      PSBars (graph, object, f, KAPA_PLOT_BARS_SOLID);
     87      break;
     88    case KAPA_PLOT_BARS_OUTLINE:
     89      PSBars (graph, object, f, KAPA_PLOT_BARS_OUTLINE);
     90      break;
     91    case KAPA_PLOT_BARS_OUTFILL:
     92      PSBars (graph, object, f, KAPA_PLOT_BARS_OUTFILL);
    7393      break;
    7494    case KAPA_PLOT_POINTS:
     
    265285  DrawLine (sx1, sy1, sxa, sy1);
    266286  DrawLine (sxa, sy1, sxa, sya);
    267 
    268 # if (0)
    269   sx0 = x[i]*mxi + y[i]*mxj + bx;
    270   sy0 = x[i]*myi + y[i]*myj + by;
    271   sx0 = MIN (MAX (sx0, X0), X1);
    272   sy0 = MAX (MIN (sy0, Y0), Y1);
    273  
    274   /* continue with rest of points */
    275   for (i++; i < object[0].Npts; i++) {
     287}
     288
     289// uses object->color
     290# define HISTOGRAM_SOLID(X_VALUE, Y_VALUE, DX_VAL) {                    \
     291  /* histogram bar corners */                                           \
     292  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     293  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     294  double symin = Xaxis;                                                 \
     295  double symax = (Y_VALUE);                                             \
     296  /* saturated values for corner coords: */                             \
     297  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     298  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     299  symin = MAX (MIN (symin, Y0), Y1);                                    \
     300  symax = MAX (MIN (symax, Y0), Y1);                                    \
     301  double dy = fabs(symax - symin);                                      \
     302  double ylow = MAX(symin, symax);                                      \
     303  FillRectangle (sxmin, ylow, (DX_VAL), dy); }
     304
     305// uses object->color
     306# define HISTOGRAM_OUTLINE(X_VALUE, Y_VALUE, DX_VAL) {                  \
     307  /* histogram bar corners */                                           \
     308  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     309  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     310  double symin = Xaxis;                                                 \
     311  double symax = (Y_VALUE);                                             \
     312  /* saturated values for corner coords: */                             \
     313  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     314  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     315  symin = MAX (MIN (symin, Y0), Y1);                                    \
     316  symax = MAX (MIN (symax, Y0), Y1);                                    \
     317  double dy = fabs(symax - symin);                                      \
     318  double ylow = MAX(symin, symax);                                      \
     319  DrawRectangle (sxmin, ylow, (DX_VAL), dy); }
     320
     321# define HISTOGRAM_OUTFILL(X_VALUE, Y_VALUE, DX_VAL) {                  \
     322  /* histogram bar corners */                                           \
     323  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     324  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     325  double symin = Xaxis;                                                 \
     326  double symax = (Y_VALUE);                                             \
     327  /* saturated values for corner coords: */                             \
     328  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     329  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     330  symin = MAX (MIN (symin, Y0), Y1);                                    \
     331  symax = MAX (MIN (symax, Y0), Y1);                                    \
     332  double dy = fabs(symax - symin);                                      \
     333  double ylow = MAX(symin, symax);                                      \
     334  FillRectangle (sxmin, ylow, (DX_VAL), dy);                            \
     335  fprintf (f, "0.00 0.00 0.00 setrgbcolor\n");                          \
     336  DrawRectangle (sxmin, ylow, (DX_VAL), dy);                            \
     337  fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(object->color)); }
     338
     339void PSBars (KapaGraphWidget *graph, Gobjects *object, FILE *f, int mode) {
     340
     341  double mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels
     342  double mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); // slope of the x-axis in y-pixels (always 0 for now)
     343  double myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels (always 0 for now)
     344  double myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); // slope of the x-axis in x-pixels
     345 
     346  // intercepts of axes
     347  double bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);
     348  double bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);
     349  double byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);
     350  double byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);
     351 
     352  double bx = bxi + bxj;
     353  double by = byi + byj;
     354 
     355  // corner coords
     356  double X0 = graph[0].axis[0].fx;
     357  double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     358  double Y0 = graph[0].axis[1].fy;
     359  double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     360  // NOTE: Y0 > Y1 (dfy is negative)
     361
     362  /* find the first valid datapoint */
     363  float *x = object[0].x;
     364  float *y = object[0].y;
     365 
     366  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx
     367     one point at a time
     368
     369     I need to know the distance to the next and prev points to calculate dx
     370     for the first point, dx is x[1] - x[0]
     371     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
     372     for the rest, dx is 0.5*(x[i+1] - x[i-1])
     373   
     374     rather than working out complex on-the-fly logic, I want to find the first and last
     375     valid point in an initial pass, then calculate the above for the remainder.
     376     TBD: make an index vector of only valid points?
     377  */
     378
     379  int Ngood = 0;
     380  ALLOCATE_PTR (goodPoint, int, object[0].Npts);
     381
     382  // x = ??, y = 0: this assumes the xaxis is parallel to the plot window (myi = 0)
     383  // note: Y0 > Y1 : y runs from large on bottom to small on top
     384  float Xaxis = by;
     385  Xaxis = MAX (Y1, MIN (Xaxis, Y0));
     386
     387  for (int i = 0; i < object[0].Npts; i++) {
    276388    if (!(finite(x[i]) && finite(y[i]))) continue;
    277     sx1 = x[i]*mxi + y[i]*mxj + bx;
    278     sy1 = x[i]*myi + y[i]*myj + by;
    279     sx1 = MIN (MAX (sx1, X0), X1);
    280     sy1 = MAX (MIN (sy1, Y0), Y1);
    281     sxa = 0.5*(sx0 + sx1);
    282     DrawLine (sx0, sy0, sxa, sy0);
    283     DrawLine (sxa, sy0, sxa, sy1);
    284     DrawLine (sxa, sy1, sx1, sy1);
    285     sx0 = sx1; sy0 = sy1;
    286   }
    287 # endif
     389
     390    // coordinate on the screen of the point:
     391    double sx1r = x[i]*mxi + y[i]*mxj + bx;
     392
     393    if (sx1r < X0) {
     394      // point to the left, skip it
     395      continue;
     396    }
     397    if (sx1r > X1) {
     398      // point to the right, skip it
     399      continue;
     400    }
     401
     402    goodPoint[Ngood] = i;
     403    Ngood ++;
     404  }
     405   
     406  if (Ngood == 0) {
     407    free (goodPoint);
     408    return;
     409  }
     410
     411  // if we only have 1 point, draw bar half the width of the screen
     412  // this works fine, but the auto limits for 1 value are somewhat silly
     413  if (Ngood == 1) {
     414    // coordinate on the screen of the point:
     415    int n = goodPoint[0];
     416    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     417    double sy1r = x[n]*myi + y[n]*myj + by;
     418
     419    float dx = 0.5*object->size*(X1 - X0);
     420   
     421    switch (mode) {
     422      case KAPA_PLOT_BARS_SOLID:
     423        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     424        break;
     425      case KAPA_PLOT_BARS_OUTLINE:
     426        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     427        break;
     428      case KAPA_PLOT_BARS_OUTFILL:
     429        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     430        break;
     431      default:
     432        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     433        break;
     434    }
     435
     436    free (goodPoint);
     437    return;
     438  }
     439
     440  // first point:
     441  {
     442    int n;
     443    n = goodPoint[1];
     444    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     445
     446    n = goodPoint[0];
     447    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     448    double sy0r = x[n]*myi + y[n]*myj + by;
     449
     450    double dx = 0.5*object->size*(sx1r - sx0r);
     451   
     452    switch (mode) {
     453      case KAPA_PLOT_BARS_SOLID:
     454        HISTOGRAM_SOLID(sx0r, sy0r, dx);
     455        break;
     456      case KAPA_PLOT_BARS_OUTLINE:
     457        HISTOGRAM_OUTLINE(sx0r, sy0r, dx);
     458        break;
     459      case KAPA_PLOT_BARS_OUTFILL:
     460        HISTOGRAM_OUTFILL(sx0r, sy0r, dx);
     461        break;
     462      default:
     463        HISTOGRAM_SOLID(sx0r, sy0r, dx);
     464        break;
     465    }
     466  }
     467
     468  for (int i = 1; i < Ngood - 1; i++) {
     469
     470    int n;
     471    n = goodPoint[i + 1];
     472    double sx2r = x[n]*mxi + y[n]*mxj + bx;
     473
     474    n = goodPoint[i - 1];
     475    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     476
     477    // below we have 2 factors of 0.5 (we want half of the average spacing)
     478    double dx = 0.5*0.5*object->size*(sx2r - sx0r);
     479
     480    n = goodPoint[i];
     481    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     482    double sy1r = x[n]*myi + y[n]*myj + by;
     483
     484    switch (mode) {
     485      case KAPA_PLOT_BARS_SOLID:
     486        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     487        break;
     488      case KAPA_PLOT_BARS_OUTLINE:
     489        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     490        break;
     491      case KAPA_PLOT_BARS_OUTFILL:
     492        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     493        break;
     494      default:
     495        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     496        break;
     497    }
     498  }
     499 
     500  // last point:
     501  {
     502    int n;
     503    n = goodPoint[Ngood - 1];
     504    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     505    double sy1r = x[n]*myi + y[n]*myj + by;
     506
     507    n = goodPoint[Ngood - 2];
     508    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     509
     510    double dx = 0.5*object->size*(sx1r - sx0r);
     511
     512    switch (mode) {
     513      case KAPA_PLOT_BARS_SOLID:
     514        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     515        break;
     516      case KAPA_PLOT_BARS_OUTLINE:
     517        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     518        break;
     519      case KAPA_PLOT_BARS_OUTFILL:
     520        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     521        break;
     522      default:
     523        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     524        break;
     525    }
     526  }
     527  free (goodPoint);
     528  return;
    288529}
    289530
     
    310551  by = byi + byj;
    311552 
    312   Graphic *graphic = GetGraphic();
    313 
     553  // scaled colors use the colormap defined for the graphic
    314554  ALLOCATE (pixel1, float, graphic[0].Npixels);
    315555  ALLOCATE (pixel2, float, graphic[0].Npixels);
     
    347587          }
    348588          D = scaleSize ? dz*z[i] : ds;
    349           DrawRectangle (sx, sy, 2*D, 2*D);
     589          DrawRectangle (sx - D, sy - D, 2*D, 2*D);
    350590        }
    351591      }
     
    605845          }
    606846          D = scaleSize ? dz*z[i] : ds;
    607           FillRectangle (sx, sy, 2*D, 2*D);
     847          FillRectangle (sx - D, sy - D, 2*D, 2*D);
    608848        }
    609849      }
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/PSTextlines.c

    r13320 r40477  
    1616      x = graph[0].textline[i].x;
    1717      y = graphic->dy - graph[0].textline[i].y;
     18      if (graph[0].textline[i].color >= 0) {
     19        fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(graph[0].textline[i].color));
     20      }
    1821      SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
    19       PSRotText (f, x, y, graph[0].textline[i].text, 5, angle);
     22      PSRotText (f, x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
    2023    }
    2124  }
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/bDrawLabels.c

    r29938 r40477  
    4040  for (i = 0; i < graph[0].Ntextline; i++) {
    4141    if (strcmp (graph[0].textline[i].text, "")) {
     42      bDrawSetColor (buffer, graph[0].textline[i].color);
    4243      angle = graph[0].textline[i].angle;
    4344      x = graph[0].textline[i].x;
    4445      y = graph[0].textline[i].y;
    4546      SetRotFont (graph[0].textline[i].font, graph[0].textline[i].size);
    46       bDrawRotText (buffer, x, y, graph[0].textline[i].text, 5, angle);
     47      bDrawRotText (buffer, x, y, graph[0].textline[i].text, graph[0].textline[i].justify, angle);
    4748    }
    4849  }
  • branches/czw_branch/20170908/Ohana/src/kapa2/src/bDrawObjects.c

    r39926 r40477  
    22
    33# define DrawLine(BUF,X1,Y1,X2,Y2) (bDrawLine (BUF, (X1), (Y1), (X2), (Y2)))
    4 # define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
    5 # define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX+1), (Y+0.5*dY+1)))
     4# define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X), (Y), (X+dX), (Y+dY)))
     5# define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X), (Y), (X+dX+1), (Y+dY+1)))
    66# define DrawCircle(BUF,X1,Y1,R) (bDrawCircle (BUF, (X1), (Y1), (R)))
    77# define FillCircle(BUF,X1,Y1,R) (bDrawCircleFill (BUF, (X1), (Y1), (R)))
     
    99# define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
    1010
    11 # define CONNECT 0
    12 # define HISTOGRAM 1
    13 # define POINTS 2
    14 
    1511static Graphic *graphic;
    1612
     
    4238    case KAPA_PLOT_HISTOGRAM:
    4339      bDrawHistogram (buffer, graph, object);
     40      break;
     41    case KAPA_PLOT_BARS_SOLID:
     42      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_SOLID);
     43      break;
     44    case KAPA_PLOT_BARS_OUTLINE:
     45      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTLINE);
     46      break;
     47    case KAPA_PLOT_BARS_OUTFILL:
     48      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTFILL);
    4449      break;
    4550    case KAPA_PLOT_POINTS:
     
    235240  DrawLine (buffer, sx1, sy1, sxa, sy1);
    236241  DrawLine (buffer, sxa, sy1, sxa, sya);
    237 
    238 # if (0)
    239   sx0 = x[i]*mxi + y[i]*mxj + bx;
    240   sy0 = x[i]*myi + y[i]*myj + by;
    241   sx0 = MIN (MAX (sx0, X0), X1);
    242   sy0 = MAX (MIN (sy0, Y0), Y1);
    243  
    244   /* continue with rest of points */
    245   for (i++; i < object[0].Npts; i++) {
     242}
     243
     244// uses object->color
     245# define HISTOGRAM_SOLID(X_VALUE, Y_VALUE, DX_VAL) {                    \
     246  /* histogram bar corners */                                           \
     247  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     248  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     249  double symin = Xaxis;                                                 \
     250  double symax = (Y_VALUE);                                             \
     251  /* saturated values for corner coords: */                             \
     252  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     253  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     254  symin = MAX (MIN (symin, Y0), Y1);                                    \
     255  symax = MAX (MIN (symax, Y0), Y1);                                    \
     256  double dy = fabs(symax - symin);                                      \
     257  double ylow = MIN(symin, symax);                                      \
     258  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy); }
     259
     260// uses object->color
     261# define HISTOGRAM_OUTLINE(X_VALUE, Y_VALUE, DX_VAL) {                  \
     262  /* histogram bar corners */                                           \
     263  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     264  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     265  double symin = Xaxis;                                                 \
     266  double symax = (Y_VALUE);                                             \
     267  /* saturated values for corner coords: */                             \
     268  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     269  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     270  symin = MAX (MIN (symin, Y0), Y1);                                    \
     271  symax = MAX (MIN (symax, Y0), Y1);                                    \
     272  double dy = fabs(symax - symin);                                      \
     273  double ylow = MIN(symin, symax);                                      \
     274  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy); }
     275
     276# define HISTOGRAM_OUTFILL(X_VALUE, Y_VALUE, DX_VAL) {                  \
     277  /* histogram bar corners */                                           \
     278  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \
     279  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \
     280  double symin = Xaxis;                                                 \
     281  double symax = (Y_VALUE);                                             \
     282  /* saturated values for corner coords: */                             \
     283  sxmin = MIN (MAX (sxmin, X0), X1);                                    \
     284  sxmax = MIN (MAX (sxmax, X0), X1);                                    \
     285  symin = MAX (MIN (symin, Y0), Y1);                                    \
     286  symax = MAX (MIN (symax, Y0), Y1);                                    \
     287  double dy = fabs(symax - symin);                                      \
     288  double ylow = MIN(symin, symax);                                      \
     289  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy);                    \
     290  bDrawSetColor (buffer, graphic->fore);                                \
     291  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy);                    \
     292  bDrawSetColor (buffer, object[0].color); }
     293
     294void bDrawBars (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode) {
     295
     296  double mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels
     297  double mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); // slope of the x-axis in y-pixels (always 0 for now)
     298  double myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels (always 0 for now)
     299  double myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); // slope of the x-axis in x-pixels
     300 
     301  // intercepts of axes
     302  double bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);
     303  double bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);
     304  double byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);
     305  double byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);
     306 
     307  double bx = bxi + bxj;
     308  double by = byi + byj;
     309 
     310  // corner coords
     311  double X0 = graph[0].axis[0].fx;
     312  double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     313  double Y0 = graph[0].axis[1].fy;
     314  double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     315
     316  /* find the first valid datapoint */
     317  float *x = object[0].x;
     318  float *y = object[0].y;
     319 
     320  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx
     321     one point at a time
     322
     323     I need to know the distance to the next and prev points to calculate dx
     324     for the first point, dx is x[1] - x[0]
     325     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
     326     for the rest, dx is 0.5*(x[i+1] - x[i-1])
     327   
     328     rather than working out complex on-the-fly logic, I want to draw the first and last
     329     valid points in an initial pass, then calculate the above for the remainder.
     330
     331     First, make an index vector of only valid points
     332  */
     333
     334  int Ngood = 0;
     335  ALLOCATE_PTR (goodPoint, int, object[0].Npts);
     336
     337  // x = ??, y = 0: this assumes the xaxis is parallel to the plot window (myi = 0)
     338  // since y runs from large on bottom to small on top, this is slightly backwards
     339  float Xaxis = by;
     340  Xaxis = MAX (Y1, MIN (Xaxis, Y0)); // MIN & MAX reversed for neg y dir
     341
     342  for (int i = 0; i < object[0].Npts; i++) {
    246343    if (!(finite(x[i]) && finite(y[i]))) continue;
    247     sx1 = x[i]*mxi + y[i]*mxj + bx;
    248     sy1 = x[i]*myi + y[i]*myj + by;
    249     sx1 = MIN (MAX (sx1, X0), X1);
    250     sy1 = MAX (MIN (sy1, Y0), Y1);
    251     sxa = 0.5*(sx0 + sx1);
    252     DrawLine (buffer, sx0, sy0, sxa, sy0);
    253     DrawLine (buffer, sxa, sy0, sxa, sy1);
    254     DrawLine (buffer, sxa, sy1, sx1, sy1);
    255     sx0 = sx1; sy0 = sy1;
    256   }
    257 # endif
     344
     345    // coordinate on the screen of the point:
     346    double sx1r = x[i]*mxi + y[i]*mxj + bx;
     347
     348    if (sx1r < X0) {
     349      // point to the left, skip it
     350      continue;
     351    }
     352    if (sx1r > X1) {
     353      // point to the right, skip it
     354      continue;
     355    }
     356
     357    goodPoint[Ngood] = i;
     358    Ngood ++;
     359  }
     360   
     361  if (Ngood == 0) {
     362    free (goodPoint);
     363    return;
     364  }
     365
     366  // if we only have 1 point, draw bar half the width of the screen
     367  // this works fine, but the auto limits for 1 value are somewhat silly
     368  if (Ngood == 1) {
     369    // coordinate on the screen of the point:
     370    int n = goodPoint[0];
     371    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     372    double sy1r = x[n]*myi + y[n]*myj + by;
     373
     374    float dx = 0.5*object->size*(X1 - X0);
     375   
     376    switch (mode) {
     377      case KAPA_PLOT_BARS_SOLID:
     378        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     379        break;
     380      case KAPA_PLOT_BARS_OUTLINE:
     381        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     382        break;
     383      case KAPA_PLOT_BARS_OUTFILL:
     384        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     385        break;
     386      default:
     387        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     388        break;
     389    }
     390
     391    free (goodPoint);
     392    return;
     393  }
     394
     395  // first point:
     396  {
     397    int n;
     398    n = goodPoint[1];
     399    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     400
     401    n = goodPoint[0];
     402    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     403    double sy0r = x[n]*myi + y[n]*myj + by;
     404
     405    double dx = 0.5*object->size*(sx1r - sx0r);
     406   
     407    switch (mode) {
     408      case KAPA_PLOT_BARS_SOLID:
     409        HISTOGRAM_SOLID(sx0r, sy0r, dx);
     410        break;
     411      case KAPA_PLOT_BARS_OUTLINE:
     412        HISTOGRAM_OUTLINE(sx0r, sy0r, dx);
     413        break;
     414      case KAPA_PLOT_BARS_OUTFILL:
     415        HISTOGRAM_OUTFILL(sx0r, sy0r, dx);
     416        break;
     417      default:
     418        HISTOGRAM_SOLID(sx0r, sy0r, dx);
     419        break;
     420    }
     421  }
     422
     423  for (int i = 1; i < Ngood - 1; i++) {
     424
     425    int n;
     426    n = goodPoint[i + 1];
     427    double sx2r = x[n]*mxi + y[n]*mxj + bx;
     428
     429    n = goodPoint[i - 1];
     430    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     431
     432    // below we have 2 factors of 0.5 (we want half of the average spacing)
     433    double dx = 0.5*0.5*object->size*(sx2r - sx0r);
     434
     435    n = goodPoint[i];
     436    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     437    double sy1r = x[n]*myi + y[n]*myj + by;
     438
     439    switch (mode) {
     440      case KAPA_PLOT_BARS_SOLID:
     441        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     442        break;
     443      case KAPA_PLOT_BARS_OUTLINE:
     444        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     445        break;
     446      case KAPA_PLOT_BARS_OUTFILL:
     447        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     448        break;
     449      default:
     450        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     451        break;
     452    }
     453  }
     454 
     455  // last point:
     456  {
     457    int n;
     458    n = goodPoint[Ngood - 1];
     459    double sx1r = x[n]*mxi + y[n]*mxj + bx;
     460    double sy1r = x[n]*myi + y[n]*myj + by;
     461
     462    n = goodPoint[Ngood - 2];
     463    double sx0r = x[n]*mxi + y[n]*mxj + bx;
     464
     465    double dx = 0.5*object->size*(sx1r - sx0r);
     466
     467    switch (mode) {
     468      case KAPA_PLOT_BARS_SOLID:
     469        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     470        break;
     471      case KAPA_PLOT_BARS_OUTLINE:
     472        HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
     473        break;
     474      case KAPA_PLOT_BARS_OUTFILL:
     475        HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
     476        break;
     477      default:
     478        HISTOGRAM_SOLID(sx1r, sy1r, dx);
     479        break;
     480    }
     481  }
     482  free (goodPoint);
     483  return;
    258484}
    259485
     
    280506  by = byi + byj;
    281507 
    282   Graphic *graphic = GetGraphic();
    283 
     508  // scaled colors use the colormap defined for the graphic
    284509  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
    285510  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
     
    293518  }
    294519
    295   /**** points are scaled by object.z ***/
     520  /**** point sizes are scaled by object.size, colors by object.color ***/
    296521  int scaleSize = (object[0].size < 0);
    297522  int scaleColor = (object[0].color < 0);
     
    317542          }
    318543          D = scaleSize ? dz*z[i] : ds;
    319           DrawRectangle (buffer, sx, sy, 2*D, 2*D);
     544          DrawRectangle (buffer, sx - D, sy - D, 2*D, 2*D); // DrawRectangle takes corner point
    320545          // plot range saturated by bDrawRectOpen
    321546        }
     
    611836          }
    612837          D = scaleSize ? dz*z[i] : ds;
    613           FillRectangle (buffer, sx, sy, 2*D, 2*D);
     838          FillRectangle (buffer, sx - D, sy - D, 2*D, 2*D);
    614839          // plot range saturated by bDrawRectFill
    615840        }
  • branches/czw_branch/20170908/Ohana/src/libautocode/Makefile.Targets

    r40062 r40477  
    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 \
  • branches/czw_branch/20170908/Ohana/src/libautocode/def/image.d

    r37807 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libautocode/def/measure.d

    r39262 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libautocode/def/secfilt.d

    r37246 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/Makefile

    r40063 r40477  
    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 \
  • branches/czw_branch/20170908/Ohana/src/libdvo/doc/notes.txt

    r34749 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/include/dvo.h

    r40063 r40477  
    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"
     
    12671272# undef LENSFIELD
    12681273
    1269 # define GALPHOT_FIELD(NAME, VALUE) float GalphotValue_##NAME (PhotCode *code, dvoMagClassType class, GalPhot *galphot, int Ngalphot)
    1270 
    1271 GALPHOT_FIELD(GAL_MAG,         mag);           
    1272 GALPHOT_FIELD(GAL_MAG_ERR,     magErr);   
    1273 GALPHOT_FIELD(GAL_MAJ,         majorAxis);             
    1274 GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr);
    1275 GALPHOT_FIELD(GAL_MIN,         minorAxis);             
    1276 GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr);   
    1277 GALPHOT_FIELD(GAL_THETA,       theta);     
    1278 GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr); 
    1279 GALPHOT_FIELD(GAL_INDEX,       index);     
    1280 GALPHOT_FIELD(GAL_CHISQ,       chisq);     
    1281 GALPHOT_FIELD(GAL_NPIX,        Npix);       
    1282 GALPHOT_FIELD(GAL_FLAGS,       flags);       
    1283 GALPHOT_FIELD(GAL_TYPE,        modelType);       
     1274# define GALPHOT_FIELD(NAME, VALUE, TYPE, DEFAULT) TYPE GalphotValue_##NAME (PhotCode *code, dvoMagClassType class, GalPhot *galphot, int Ngalphot);
     1275
     1276//GALPHOT_FIELD(GAL_MAG,               mag);           
     1277//GALPHOT_FIELD(GAL_MAG_ERR,     magErr);   
     1278//GALPHOT_FIELD(GAL_MAJ,               majorAxis);             
     1279//GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr);
     1280//GALPHOT_FIELD(GAL_MIN,               minorAxis);             
     1281//GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr);   
     1282//GALPHOT_FIELD(GAL_THETA,       theta);     
     1283//GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr); 
     1284//GALPHOT_FIELD(GAL_INDEX,       index);     
     1285//GALPHOT_FIELD(GAL_CHISQ,       chisq);     
     1286//GALPHOT_FIELD(GAL_NPIX,        Npix);       
     1287//GALPHOT_FIELD(GAL_FLAGS,       flags);       
     1288//GALPHOT_FIELD(GAL_TYPE,        modelType);       
     1289
     1290GALPHOT_FIELD(GAL_MAG,         mag,          float, NAN)
     1291GALPHOT_FIELD(GAL_MAG_ERR,     magErr,       float, NAN)
     1292GALPHOT_FIELD(GAL_MAJ,         majorAxis,    float, NAN)
     1293GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr, float, NAN)
     1294GALPHOT_FIELD(GAL_MIN,         minorAxis,    float, NAN)
     1295GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr, float, NAN)
     1296GALPHOT_FIELD(GAL_THETA,       theta,        float, NAN)
     1297GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr,     float, NAN)
     1298GALPHOT_FIELD(GAL_INDEX,       index,        float, NAN)     
     1299GALPHOT_FIELD(GAL_CHISQ,       chisq,        float, NAN)     
     1300GALPHOT_FIELD(GAL_NPIX,        Npix,         float, NAN)       
     1301
     1302GALPHOT_FIELD(GAL_TYPE,        modelType,    short, 0)       
     1303
     1304GALPHOT_FIELD(GAL_FLAGS,       flags,        unsigned int, 0)       
     1305GALPHOT_FIELD(GAL_OBJ_ID,      objID,        unsigned int, 0)       
     1306GALPHOT_FIELD(GAL_CAT_ID,      catID,        unsigned int, 0)       
     1307GALPHOT_FIELD(GAL_DET_ID,      detID,        unsigned int, 0)       
     1308GALPHOT_FIELD(GAL_IMAGE_ID,    imageID,      unsigned int, 0)       
    12841309
    12851310# undef GALPHOT_FIELD
  • branches/czw_branch/20170908/Ohana/src/libdvo/include/dvodb.h

    r39633 r40477  
    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 {
     
    120127  MAG_OPTION_GAL_FLAGS,       
    121128  MAG_OPTION_GAL_TYPE,       
     129
     130  MAG_OPTION_GAL_OBJ_ID, 
     131  MAG_OPTION_GAL_CAT_ID, 
     132  MAG_OPTION_GAL_DET_ID,
     133  MAG_OPTION_GAL_IMAGE_ID,
    122134} dvoMagOptionType;
    123135
     
    236248      MEAS_EXTERN_ID,
    237249      MEAS_EXPNAME_AS_INT,
    238       MEAS_MCAL_OFFSET, // make this a dvoMagOption?
     250      MEAS_MCAL_OFFSET_PSF, // make this a dvoMagOption?
     251      MEAS_MCAL_OFFSET_APER, // make this a dvoMagOption?
    239252      MEAS_FLAT,
    240253      MEAS_CENTER_OFFSET,
     
    369382      IMAGE_XM,
    370383      IMAGE_AIRMASS,
    371       IMAGE_MCAL,
     384      IMAGE_MCAL_PSF,
     385      IMAGE_MCAL_APER,
    372386      IMAGE_dMCAL,
    373387      IMAGE_PHOTCODE,
     
    471485  char    type;
    472486  int     field;
    473   // opihi_flt FltValue;
    474   // opihi_int IntValue;
    475   double FltValue;
    476   int IntValue;
     487  opihi_flt FltValue;
     488  opihi_int IntValue;
     489  // double FltValue;
     490  // int IntValue;
    477491} dbStack;
    478492
    479493typedef struct {
    480   // opihi_flt Flt;
    481   // opihi_int Int;
    482   double Flt;
    483   int Int;
     494  opihi_flt Flt;
     495  opihi_int Int;
     496  // double Flt;
     497  // int Int;
    484498} dbValue;
    485499
     
    562576int dbExtractImagesReset (void);
    563577
    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 
    569578#include "get_graphdata.h"
    570579
  • branches/czw_branch/20170908/Ohana/src/libdvo/include/libdvo_astro.h

    r39457 r40477  
    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)
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/HostTable.c

    r39475 r40477  
    1111  host->stdio[HOST_STDERR] = -1;
    1212  host->pid = 0;
     13  host->status = 1024;
    1314  return;
    1415}
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/ImageMetadata.c

    r37807 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r40063 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r38553 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dbCheckStack.c

    r39578 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dbExtractAverages.c

    r39633 r40477  
    466466          break;
    467467
    468         case MAG_OPTION_GAL_MAG:       { value.Flt = GalphotValue_GAL_MAG      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    469         case MAG_OPTION_GAL_MAG_ERR:   { value.Flt = GalphotValue_GAL_MAG_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    470         case MAG_OPTION_GAL_MAJ:       { value.Flt = GalphotValue_GAL_MAJ      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    471         case MAG_OPTION_GAL_MAJ_ERR:   { value.Flt = GalphotValue_GAL_MAJ_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    472         case MAG_OPTION_GAL_MIN:       { value.Flt = GalphotValue_GAL_MIN      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    473         case MAG_OPTION_GAL_MIN_ERR:   { value.Flt = GalphotValue_GAL_MIN_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    474         case MAG_OPTION_GAL_THETA:     { value.Flt = GalphotValue_GAL_THETA    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    475         case MAG_OPTION_GAL_THETA_ERR: { value.Flt = GalphotValue_GAL_THETA_ERR(field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    476         case MAG_OPTION_GAL_INDEX:     { value.Flt = GalphotValue_GAL_INDEX    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    477         case MAG_OPTION_GAL_CHISQ:     { value.Flt = GalphotValue_GAL_CHISQ    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    478         case MAG_OPTION_GAL_NPIX:      { value.Flt = GalphotValue_GAL_NPIX     (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    479         case MAG_OPTION_GAL_TYPE:      { value.Flt = GalphotValue_GAL_TYPE     (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    480         case MAG_OPTION_GAL_FLAGS:     { value.Flt = GalphotValue_GAL_FLAGS    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     468        case MAG_OPTION_GAL_MAG:      { value.Flt = GalphotValue_GAL_MAG      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     469        case MAG_OPTION_GAL_MAG_ERR:  { value.Flt = GalphotValue_GAL_MAG_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     470        case MAG_OPTION_GAL_MAJ:      { value.Flt = GalphotValue_GAL_MAJ      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     471        case MAG_OPTION_GAL_MAJ_ERR:  { value.Flt = GalphotValue_GAL_MAJ_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     472        case MAG_OPTION_GAL_MIN:      { value.Flt = GalphotValue_GAL_MIN      (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     473        case MAG_OPTION_GAL_MIN_ERR:  { value.Flt = GalphotValue_GAL_MIN_ERR  (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     474        case MAG_OPTION_GAL_THETA:    { value.Flt = GalphotValue_GAL_THETA    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     475        case MAG_OPTION_GAL_THETA_ERR:{ value.Flt = GalphotValue_GAL_THETA_ERR(field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     476        case MAG_OPTION_GAL_INDEX:    { value.Flt = GalphotValue_GAL_INDEX    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     477        case MAG_OPTION_GAL_CHISQ:    { value.Flt = GalphotValue_GAL_CHISQ    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     478        case MAG_OPTION_GAL_NPIX:     { value.Flt = GalphotValue_GAL_NPIX     (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     479        case MAG_OPTION_GAL_TYPE:     { value.Flt = GalphotValue_GAL_TYPE     (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     480        case MAG_OPTION_GAL_FLAGS:    { value.Flt = GalphotValue_GAL_FLAGS    (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     481
     482        case MAG_OPTION_GAL_OBJ_ID:   { value.Flt = GalphotValue_GAL_OBJ_ID   (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     483        case MAG_OPTION_GAL_CAT_ID:   { value.Flt = GalphotValue_GAL_CAT_ID   (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     484        case MAG_OPTION_GAL_DET_ID:   { value.Flt = GalphotValue_GAL_DET_ID   (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
     485        case MAG_OPTION_GAL_IMAGE_ID: { value.Flt = GalphotValue_GAL_IMAGE_ID (field->photcode, field->magClass, galphot, average->Ngalphot); break; }
    481486
    482487        default:
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dbExtractImages.c

    r39457 r40477  
    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:
     
    374377      break;
    375378    case IMAGE_Y_ERR_SYS:
    376       value.Flt = image[N].dXpixSys;
     379      value.Flt = image[N].dYpixSys;
    377380      break;
    378381    case IMAGE_MAG_ERR_SYS:
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dbExtractMeasures.c

    r39926 r40477  
    316316        case MAG_OPTION_GAL_FLAGS:     
    317317        case MAG_OPTION_GAL_TYPE:     
     318        case MAG_OPTION_GAL_OBJ_ID:
     319        case MAG_OPTION_GAL_CAT_ID:
     320        case MAG_OPTION_GAL_DET_ID:
     321        case MAG_OPTION_GAL_IMAGE_ID:
    318322
    319323        case MAG_OPTION_NONE:
     
    696700      break;
    697701    case MEAS_PSF_QF_PERFECT: /* OK */
    698       value.Flt = NAN;
     702      value.Flt = measure[0].psfQFperf;
    699703      break;
    700704    case MEAS_PSF_CHISQ: /* OK */
     
    740744      break;
    741745
    742     case MEAS_MCAL_OFFSET: { value.Flt = measure[0].Mcal; break; }
     746    case MEAS_MCAL_OFFSET_PSF:  { value.Flt = measure[0].McalPSF;  break; }
     747    case MEAS_MCAL_OFFSET_APER: { value.Flt = measure[0].McalAPER; break; }
    743748    case MEAS_FLAT: { value.Flt = measure[0].Mflat; break; }
    744749
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dbFields.c

    r40206 r40477  
    181181  if (magOption == MAG_OPTION_GAL_FLAGS       ) return TRUE;
    182182  if (magOption == MAG_OPTION_GAL_TYPE        ) return TRUE;
     183
     184  if (magOption == MAG_OPTION_GAL_OBJ_ID      ) return TRUE;
     185  if (magOption == MAG_OPTION_GAL_CAT_ID      ) return TRUE;
     186  if (magOption == MAG_OPTION_GAL_DET_ID      ) return TRUE;
     187  if (magOption == MAG_OPTION_GAL_IMAGE_ID    ) return TRUE;
    183188  return FALSE;
    184189}
     
    609614  if (!strcasecmp (fieldName, "SKY"))            ESCAPE (MEAS_SKY,            OPIHI_FLT);
    610615  if (!strcasecmp (fieldName, "SKY_ERR"))        ESCAPE (MEAS_dSKY,           OPIHI_FLT);
    611   if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET,    OPIHI_FLT);
     616  if (!strcasecmp (fieldName, "MCAL_OFFSET"))    ESCAPE (MEAS_MCAL_OFFSET_PSF,    OPIHI_FLT);
     617  if (!strcasecmp (fieldName, "MCAL_OFFSET_PSF"))  ESCAPE (MEAS_MCAL_OFFSET_PSF,  OPIHI_FLT);
     618  if (!strcasecmp (fieldName, "MCAL_OFFSET_APER")) ESCAPE (MEAS_MCAL_OFFSET_APER, OPIHI_FLT);
    612619  if (!strcasecmp (fieldName, "FLAT"))           ESCAPE (MEAS_FLAT,           OPIHI_FLT);
    613620  if (!strcasecmp (fieldName, "CENTER_OFFSET"))  ESCAPE (MEAS_CENTER_OFFSET,  OPIHI_FLT);
     
    845852  if (!strcasecmp (fieldName, "dapresid" )) ESCAPE (IMAGE_DAPRESID,  OPIHI_FLT);
    846853
    847   if (!strcasecmp (fieldName, "Mcal"     )) ESCAPE (IMAGE_MCAL,      OPIHI_FLT);
    848   if (!strcasecmp (fieldName, "dMcal"    )) ESCAPE (IMAGE_dMCAL,     OPIHI_FLT);
    849   if (!strcasecmp (fieldName, "Xm"       )) ESCAPE (IMAGE_XM,        OPIHI_FLT);
    850   if (!strcasecmp (fieldName, "photcode" )) ESCAPE (IMAGE_PHOTCODE,  OPIHI_INT);
    851   if (!strcasecmp (fieldName, "exptime"  )) ESCAPE (IMAGE_EXPTIME,   OPIHI_FLT);
    852   if (!strcasecmp (fieldName, "expname"  )) ESCAPE (IMAGE_EXPNAME_AS_INT, OPIHI_INT);
    853   if (!strcasecmp (fieldName, "sidtime"  )) ESCAPE (IMAGE_SIDTIME,   OPIHI_FLT);
     854  if (!strcasecmp (fieldName, "Mcal"        )) ESCAPE (IMAGE_MCAL_PSF,       OPIHI_FLT);
     855  if (!strcasecmp (fieldName, "McalPSF"     )) ESCAPE (IMAGE_MCAL_PSF,       OPIHI_FLT);
     856  if (!strcasecmp (fieldName, "McalAPER"    )) ESCAPE (IMAGE_MCAL_APER,      OPIHI_FLT);
     857  if (!strcasecmp (fieldName, "McalAPERTURE")) ESCAPE (IMAGE_MCAL_APER,      OPIHI_FLT);
     858  if (!strcasecmp (fieldName, "dMcal"       )) ESCAPE (IMAGE_dMCAL,          OPIHI_FLT);
     859  if (!strcasecmp (fieldName, "Xm"          )) ESCAPE (IMAGE_XM,             OPIHI_FLT);
     860  if (!strcasecmp (fieldName, "photcode"    )) ESCAPE (IMAGE_PHOTCODE,       OPIHI_INT);
     861  if (!strcasecmp (fieldName, "exptime"     )) ESCAPE (IMAGE_EXPTIME,        OPIHI_FLT);
     862  if (!strcasecmp (fieldName, "expname"     )) ESCAPE (IMAGE_EXPNAME_AS_INT, OPIHI_INT);
     863  if (!strcasecmp (fieldName, "sidtime"     )) ESCAPE (IMAGE_SIDTIME,        OPIHI_FLT);
    854864
    855865  if (!strcasecmp (fieldName, "latitude" )) ESCAPE (IMAGE_LATITUDE,  OPIHI_FLT);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_catalog.c

    r40063 r40477  
    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    }
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r40063 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_catalog_split.c

    r39395 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert.c

    r40063 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r37807 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_REF.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_SIM.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V1.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V2.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V3.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V5.c

    r39486 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_PS1_V5_LOAD.c

    r40063 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r38462 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r38462 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_image.c

    r40063 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_image_raw.c

    r40063 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r39670 r40477  
    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 
     
    21222137LENSFIELD(E2)
    21232138
    2124 # if (1)
     2139# if (0)
    21252140float GalphotValue_GAL_MAG (PhotCode *code, dvoMagClassType class, GalPhot *galphot, int Ngalphot) {
    21262141  int n;                                                                 
     
    21502165# endif
    21512166
    2152 # define GALPHOT_FIELD(NAME, VALUE)                                     \
    2153   float GalphotValue_##NAME (PhotCode *code, dvoMagClassType class, GalPhot *galphot, int Ngalphot) { \
     2167// the block above is an example of the generic version below
     2168
     2169# define GALPHOT_FIELD(NAME, VALUE, TYPE, DEFAULT)                              \
     2170  TYPE GalphotValue_##NAME (PhotCode *code, dvoMagClassType class, GalPhot *galphot, int Ngalphot) { \
    21542171    int n;                                                              \
    2155     if (code == NULL) return NAN;                                       \
     2172    if (code == NULL) return DEFAULT;                                   \
    21562173    for (n = 0; n < Ngalphot; n++) {                                    \
    21572174      short equivCode = GetPhotcodeEquivCodebyCode (galphot[n].photcode); \
     
    21692186          break;                                                        \
    21702187        default:                                                        \
    2171           return NAN;                                                   \
     2188          return DEFAULT;                                               \
    21722189      }                                                                 \
    2173       float value = galphot[n].VALUE;                                   \
     2190      TYPE value = galphot[n].VALUE;                                    \
    21742191      return (value);                                                   \
    21752192    }                                                                   \
    2176     return NAN;                                                         \
    2177   }
    2178 
    2179 // GALPHOT_FIELD(GAL_MAG,              mag)
    2180 GALPHOT_FIELD(GAL_MAG_ERR,     magErr)
    2181 GALPHOT_FIELD(GAL_MAJ,         majorAxis)
    2182 GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr)
    2183 GALPHOT_FIELD(GAL_MIN,         minorAxis)
    2184 GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr)
    2185 GALPHOT_FIELD(GAL_THETA,       theta)
    2186 GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr)
    2187 GALPHOT_FIELD(GAL_INDEX,       index)     
    2188 GALPHOT_FIELD(GAL_CHISQ,       chisq)     
    2189 GALPHOT_FIELD(GAL_NPIX,        Npix)       
    2190 GALPHOT_FIELD(GAL_FLAGS,       flags)       
    2191 GALPHOT_FIELD(GAL_TYPE,        modelType)       
     2193    return DEFAULT;                                                     \
     2194  }
     2195
     2196GALPHOT_FIELD(GAL_MAG,         mag,          float, NAN)
     2197GALPHOT_FIELD(GAL_MAG_ERR,     magErr,       float, NAN)
     2198GALPHOT_FIELD(GAL_MAJ,         majorAxis,    float, NAN)
     2199GALPHOT_FIELD(GAL_MAJ_ERR,     majorAxisErr, float, NAN)
     2200GALPHOT_FIELD(GAL_MIN,         minorAxis,    float, NAN)
     2201GALPHOT_FIELD(GAL_MIN_ERR,     minorAxisErr, float, NAN)
     2202GALPHOT_FIELD(GAL_THETA,       theta,        float, NAN)
     2203GALPHOT_FIELD(GAL_THETA_ERR,   thetaErr,     float, NAN)
     2204GALPHOT_FIELD(GAL_INDEX,       index,        float, NAN)     
     2205GALPHOT_FIELD(GAL_CHISQ,       chisq,        float, NAN)     
     2206GALPHOT_FIELD(GAL_NPIX,        Npix,         float, NAN)       
     2207
     2208GALPHOT_FIELD(GAL_TYPE,        modelType,    short, 0)       
     2209
     2210GALPHOT_FIELD(GAL_FLAGS,       flags,        unsigned int, 0)       
     2211GALPHOT_FIELD(GAL_OBJ_ID,      objID,        unsigned int, 0)       
     2212GALPHOT_FIELD(GAL_CAT_ID,      catID,        unsigned int, 0)       
     2213GALPHOT_FIELD(GAL_DET_ID,      detID,        unsigned int, 0)       
     2214GALPHOT_FIELD(GAL_IMAGE_ID,    imageID,      unsigned int, 0)       
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvo_tiny_values.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/dvosorts.c

    r39457 r40477  
    77
    88# define SWAPFUNC(A,B){ Average tmp; tmp = ave[A]; ave[A] = ave[B]; ave[B] = tmp; }
    9 # define COMPARE(A,B)(ave[A].R < ave[B].R)
     9# define COMPARE(A,B)((!isfinite(ave[A].R) && isfinite(ave[B].R)) || (ave[A].R < ave[B].R))
     10// # define COMPARE(A,B)                                             (ave[A].R < ave[B].R)
    1011
    1112  OHANA_SORT (N, COMPARE, SWAPFUNC);
     
    5051  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
    5152}
    52 # define COMPARE(A,B)(X[A] < X[B])
     53// # define COMPARE(A,B)                                     (X[A] < X[B])
     54# define COMPARE(A,B)((!isfinite(X[A]) && isfinite(X[B])) || (X[A] < X[B]))
    5355
    5456  OHANA_SORT (N, COMPARE, SWAPFUNC);
     
    8183  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
    8284}
    83 # define COMPARE(A,B)(X[S[A]] < X[S[B]])
     85# define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))
    8486
    8587  OHANA_SORT (N, COMPARE, SWAPFUNC);
     
    9395
    9496# define SWAPFUNC(A,B){ SkyRegion tmp; tmp = region[A]; region[A] = region[B]; region[B] = tmp; }
    95 # define COMPARE(A,B)(region[A].Dmin < region[B].Dmin)
     97// # define COMPARE(A,B)(region[A].Dmin < region[B].Dmin)
     98# define COMPARE(A,B)((!isfinite(region[A].Dmin) && isfinite(region[B].Dmin)) || (region[A].Dmin < region[B].Dmin))
    9699
    97100  OHANA_SORT (N, COMPARE, SWAPFUNC);
  • branches/czw_branch/20170908/Ohana/src/libdvo/src/skyregion_ops.c

    r39301 r40477  
    319319
    320320// a region like -10 10 0 20 will become 350 10 0 20 and return all regions on both sides of 0,360
     321// a region like -10 370 should NOT become 350 10, but should instead become 0 360
    321322SkyList *SkyListByBounds (SkyTable *table, int depth, double Rmin, double Rmax, double Dmin, double Dmax) {
    322323
    323324  int i, j, Ns;
    324325  SkyList *list, *extra;
     326
     327  if (Rmax - Rmin > 360.0) {
     328    Rmin =   0.0;
     329    Rmax = 360.0;
     330  }
    325331
    326332  Rmin = ohana_normalize_angle (Rmin);
  • branches/czw_branch/20170908/Ohana/src/libkapa/include/kapa.h

    r40106 r40477  
    239239int KapaSetFont (int fd, char *name, int size);
    240240int KapaSendLabel (int fd, char *string, int mode);
    241 int KapaSendTextline (int fd, char *string, float x, float y, float angle);
     241int KapaSendTextline (int fd, char *string, float x, float y, float angle, int justify, int color);
    242242int KapaSetLimits (int fd, Graphdata *graphmode);
    243243int KapaGetLimits (int fd, float *dx, float *dy);
     
    292292void bDrawBufferFree (bDrawBuffer *buffer);
    293293void bDrawSetBuffer (bDrawBuffer *buffer);
     294void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color);
    294295void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt);
    295296void bDrawPoint (bDrawBuffer *buffer, int x, int y);
  • branches/czw_branch/20170908/Ohana/src/libkapa/src/DrawRotString.c

    r39626 r40477  
    1212static unsigned long RotBackground;
    1313
     14// fore and back are X colors
    1415int DrawRotTextInit (Display *display, Window window, GC gc, unsigned long fore, unsigned long back) {
    1516
  • branches/czw_branch/20170908/Ohana/src/libkapa/src/KapaWindow.c

    r39926 r40477  
    9494  graphdata[0].xmax = graphdata[0].ymax = 1.0;
    9595
    96   graphdata[0].style = graphdata[0].ptype = 2;
     96  graphdata[0].style = KAPA_PLOT_POINTS;
     97  graphdata[0].ptype = KAPA_POINT_BOX_SOLID;
    9798  graphdata[0].ltype = graphdata[0].color = 0;
    9899  graphdata[0].etype = graphdata[0].ebar = 0;
     
    357358}
    358359
    359 int KapaSendTextline (int fd, char *string, float x, float y, float angle) {
    360  
     360int KapaSendTextline (int fd, char *string, float x, float y, float angle, int justify, int color) {
     361 
     362  // must be in range 0 - 8
     363  justify = MIN(MAX(justify, 0), 8);
     364
    361365  KiiSendCommand (fd, 4, "PTXT");
    362   KiiSendMessage (fd, "%f %f %f ", x, y, angle);
     366  KiiSendMessage (fd, "%f %f %f %d %d", x, y, angle, justify, color);
    363367  KiiSendData (fd, string, strlen(string));
    364368  KiiWaitAnswer (fd, "DONE");
  • branches/czw_branch/20170908/Ohana/src/libkapa/src/PSRotFont.c

    r39457 r40477  
    9090    /* check for special characters */
    9191    if (!code && !protect) {
    92       /* superscript character (^) */
     92      /* subscript character (_) */
    9393      if (N == 94) {
    9494        PSDumpRotSegment (f, segment, &Nseg);
    95         SetRotFont (currentname, (int)(0.8*currentsize));
     95        PSSetFont (f, currentname, (int)(0.8*currentsize));
    9696        currentfont = GetRotFontData (&currentscale);
    9797        Yoff = 0.75*currentscale*dY;
    9898        fprintf (f, "0 %d rmoveto\n", Yoff);
    9999        YoffBase += Yoff;
    100         PSSetFont (f, currentname, currentsize);
    101         continue;
    102       }
    103       /* subscript character (_) */
     100        // PSSetFont (f, currentname, currentsize);
     101        continue;
     102      }
     103      /* superscript character (^) */
    104104      if (N == 95) {
    105105        PSDumpRotSegment (f, segment, &Nseg);
    106         SetRotFont (currentname, (int)(0.8*currentsize));
     106        PSSetFont (f, currentname, (int)(0.8*currentsize));
    107107        currentfont = GetRotFontData (&currentscale);
    108108        Yoff = -0.5*currentscale*dY;
    109109        fprintf (f, "0 %d rmoveto\n", Yoff);
    110110        YoffBase += Yoff;
    111         PSSetFont (f, currentname, currentsize);
     111        // PSSetFont (f, currentname, currentsize);
    112112        continue;
    113113      }
     
    115115      if (N == 124) {
    116116        PSDumpRotSegment (f, segment, &Nseg);
    117         SetRotFont (currentname, basesize);
     117        PSSetFont (f, currentname, basesize);
    118118        currentfont = GetRotFontData (&currentscale);
    119119        fprintf (f, "0 %d rmoveto\n", -YoffBase);
    120120        YoffBase = 0;
    121         PSSetFont (f, currentname, currentsize);
     121        // PSSetFont (f, currentname, currentsize);
    122122        continue;
    123123      }
     
    145145        PSDumpRotSegment (f, segment, &Nseg);
    146146        if (string[i+1] == 'h') {
    147           SetRotFont ("helvetica", currentsize);
    148           currentfont = GetRotFontData (&currentscale);
    149           PSSetFont (f, currentname, currentsize);
     147          PSSetFont (f, "helvetica", currentsize);
     148          currentfont = GetRotFontData (&currentscale);
     149          // PSSetFont (f, currentname, currentsize);
    150150        }
    151151        if (string[i+1] == 't') {
    152           SetRotFont ("times", currentsize);
    153           currentfont = GetRotFontData (&currentscale);
    154           PSSetFont (f, currentname, currentsize);
     152          PSSetFont (f, "times", currentsize);
     153          currentfont = GetRotFontData (&currentscale);
     154          // PSSetFont (f, currentname, currentsize);
    155155        }
    156156        if (string[i+1] == 'c') {
    157           SetRotFont ("courier", currentsize);
    158           currentfont = GetRotFontData (&currentscale);
    159           PSSetFont (f, currentname, currentsize);
     157          PSSetFont (f, "courier", currentsize);
     158          currentfont = GetRotFontData (&currentscale);
     159          // PSSetFont (f, currentname, currentsize);
    160160        }
    161161        if (string[i+1] == 's') {
    162           SetRotFont ("symbol", currentsize);
    163           currentfont = GetRotFontData (&currentscale);
    164           PSSetFont (f, currentname, currentsize);
     162          PSSetFont (f, "symbol", currentsize);
     163          currentfont = GetRotFontData (&currentscale);
     164          // PSSetFont (f, currentname, currentsize);
    165165        }
    166166        i++;
     
    176176  fprintf (f, "stroke grestore\n");
    177177  free (segment);
    178   SetRotFont (basename, basesize);
     178  PSSetFont (f, basename, basesize);
    179179}
    180180
  • branches/czw_branch/20170908/Ohana/src/libkapa/src/bDrawFuncs.c

    r39926 r40477  
    7676// }
    7777
    78 void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
     78// "bDrawColor color" is one of the hardwired colors in KapaColors.c
     79void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color) {
    7980  buffer->bColor = color;
    8081  buffer->bColor_R = buffer->palette[color].red;
    8182  buffer->bColor_G = buffer->palette[color].green;
    8283  buffer->bColor_B = buffer->palette[color].blue;
     84
     85  return;
     86}
     87
     88void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
     89  bDrawSetColor (buffer, color);
    8390
    8491  buffer->bWeight = lw;
     
    121128}
    122129
     130// x1,y1 is lower-left corner, x2,y2 is upper-right corner
    123131void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
    124132
  • branches/czw_branch/20170908/Ohana/src/libohana/include/ohana.h

    r39457 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libohana/include/ohana_sort.h

    r38986 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/libohana/src/bisection.c

    r38459 r40477  
    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}
  • branches/czw_branch/20170908/Ohana/src/libohana/src/errors.c

    r31635 r40477  
    11# include "ohana.h"
    22
    3 static char errorline[1024];
     3int Nline = 0;
     4int NLINE = 0;
     5char **errorlines = NULL;
    46
    57int init_error () {
    68
    7   bzero (errorline, 1024);
     9  if (!errorlines) {
     10    NLINE = 10;
     11    ALLOCATE (errorlines, char *, NLINE);
     12    for (int i = 0; i < NLINE; i++) {
     13      errorlines[i] = NULL;
     14    }
     15  }
     16
     17  for (int i = 0; i < NLINE; i++) {
     18    FREE (errorlines[i]);
     19    errorlines[i] = NULL;
     20  }
     21
     22  Nline = 0;
     23
    824  return (TRUE);
    925}
     
    1127int push_error (char *line) {
    1228
    13   bzero (errorline, 1024);
    14   strncpy (errorline, line, 1023);
     29  errorlines[Nline] = strcreate (line);
     30  Nline ++;
     31
     32  if (Nline >= NLINE) {
     33    NLINE += 10;
     34    REALLOCATE (errorlines, char *, NLINE);
     35    for (int i = Nline; i < NLINE; i++) {
     36      errorlines[i] = NULL;
     37    }
     38  }
     39
    1540  return (TRUE);
    1641}
     
    1843int print_error () {
    1944
    20   gprint (GP_ERR, "%s\n", errorline);
     45  for (int i = 0; i < Nline; i++) {
     46    gprint (GP_ERR, "%s\n", errorlines[i]);
     47  }
     48 
     49  init_error();
     50
    2151  return (TRUE);
    2252}
  • branches/czw_branch/20170908/Ohana/src/libohana/src/isolate_elements.c

    r40205 r40477  
    171171  // order matches convert_to_RPN.c
    172172  if (!strncmp (c, "?",  1)) return (TRUE);
     173
    173174  // 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);
  • branches/czw_branch/20170908/Ohana/src/libohana/src/sorts.c

    r38986 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/markrock/src/find_slow_rocks.c

    r2490 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/Makefile

    r39591 r40477  
    8282$(SRC)/wcs.$(ARCH).o         \
    8383$(SRC)/imsub.$(ARCH).o             \
     84$(SRC)/jdtolst.$(ARCH).o                   \
    8485$(SRC)/imfit.$(ARCH).o             \
    8586$(SRC)/imfit-fgauss.$(ARCH).o      \
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/cdot.c

    r34088 r40477  
    2222
    2323  /* set point style and errorbar mode (these are NOT sticky) */
    24   graphmode.style = 2;
     24  graphmode.style = KAPA_PLOT_POINTS; /* points */
    2525  graphmode.etype = 0;
    2626
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/cgrid.c

    r34584 r40477  
    9595  }
    9696
     97  int JustifyRA = 5;
     98  double JustifyDEC = 5;
     99  if ((N = get_argument (argc, argv, "-justify-ra"))) {
     100    remove_argument (N, &argc, argv);
     101    JustifyRA = atoi (argv[N]);
     102    remove_argument (N, &argc, argv);
     103  }
     104  if ((N = get_argument (argc, argv, "-justify-dec"))) {
     105    remove_argument (N, &argc, argv);
     106    JustifyDEC = atoi (argv[N]);
     107    remove_argument (N, &argc, argv);
     108  }
     109
     110  double LabelRA = NAN;
     111  double LabelDEC = NAN;
     112  if ((N = get_argument (argc, argv, "-label-ra"))) {
     113    remove_argument (N, &argc, argv);
     114    LabelRA = atof (argv[N]);
     115    remove_argument (N, &argc, argv);
     116  }
     117  if ((N = get_argument (argc, argv, "-label-dec"))) {
     118    remove_argument (N, &argc, argv);
     119    LabelDEC = atof (argv[N]);
     120    remove_argument (N, &argc, argv);
     121  }
     122
     123  int LabelColor = KapaColorByName ("black");
     124  if ((N = get_argument (argc, argv, "-label-color"))) {
     125    remove_argument (N, &argc, argv);
     126    LabelColor = KapaColorByName (argv[N]);
     127    if (LabelColor == -1) return (FALSE);
     128    remove_argument (N, &argc, argv);
     129  }
     130
    97131  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    98132
     
    196230  if (Labels) {
    197231    char line[16], format[8];
    198     double xt, yt, dx, dy, frac;
    199     dx = +0.01 * (graphmode.xmax - graphmode.xmin);
    200     dy = -0.02 * (graphmode.ymax - graphmode.ymin);
    201 
     232    double xt, yt, frac;
     233    // dx = +0.01 * (graphmode.xmax - graphmode.xmin);
     234    // dy = -0.02 * (graphmode.ymax - graphmode.ymin);
     235
     236    if (isnan(LabelRA)) LabelRA = graphmode.coords.crval1;
     237    if (isnan(LabelDEC)) LabelDEC = graphmode.coords.crval2;
    202238    for (r = firstRA; r <= graphmode.coords.crval1 + 180.0; r += minorRA) {
    203       status = RD_to_XY (&xt, &yt, r, graphmode.coords.crval2, &graphmode.coords);
     239      status = RD_to_XY (&xt, &yt, r, LabelDEC, &graphmode.coords);
    204240      if (!status) continue;
    205241      if (xt < graphmode.xmin) continue;
     
    212248      }
    213249      if (frac <= 0.0) frac = 0.0;
    214       snprintf (format, 8, "%%.%df", (int) frac);
    215250      if (RAbyHour) {
     251        snprintf (format, 8, "%%.%df^h", (int) frac);
    216252        snprintf (line, 16, format, r / 15.0);
    217253      } else {
     254        snprintf (format, 8, "%%.%df^o", (int) frac);
    218255        snprintf (line, 16, format, r);
    219256      }
    220       KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
     257      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyRA, LabelColor);
    221258    }
    222259    for (r = firstRA; r >= graphmode.coords.crval1 - 180.0; r -= minorRA) {
    223       status = RD_to_XY (&xt, &yt, r, graphmode.coords.crval2, &graphmode.coords);
     260      status = RD_to_XY (&xt, &yt, r, LabelDEC, &graphmode.coords);
    224261      if (!status) continue;
    225262      if (xt < graphmode.xmin) continue;
     
    232269      }
    233270      if (frac <= 0.0) frac = 0.0;
    234       snprintf (format, 8, "%%.%df", (int) frac);
    235271      if (RAbyHour) {
     272        snprintf (format, 8, "%%.%df^h", (int) frac);
    236273        snprintf (line, 16, format, r / 15.0);
    237274      } else {
     275        snprintf (format, 8, "%%.%df^o", (int) frac);
    238276        snprintf (line, 16, format, r);
    239277      }
    240       KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
     278      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyRA, LabelColor);
    241279    }
    242280    for (d = firstDEC; d <= graphmode.coords.crval2 + 90.0; d += minorDEC) {
    243       status = RD_to_XY (&xt, &yt, graphmode.coords.crval1, d, &graphmode.coords);
     281      status = RD_to_XY (&xt, &yt, LabelRA, d, &graphmode.coords);
    244282      if (!status) continue;
    245283      if (xt < graphmode.xmin) continue;
     
    252290      }
    253291      if (frac <= 0.0) frac = 0.0;
    254       snprintf (format, 8, "%%.%df", (int) frac);
     292      snprintf (format, 8, "%%.%df^o", (int) frac);
    255293      snprintf (line, 16, format, d);
    256       KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
     294      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyDEC, LabelColor);
    257295    }
    258296    for (d = firstDEC; d >= graphmode.coords.crval2 - 90.0; d -= minorDEC) {
    259       status = RD_to_XY (&xt, &yt, graphmode.coords.crval1, d, &graphmode.coords);
     297      status = RD_to_XY (&xt, &yt, LabelRA, d, &graphmode.coords);
    260298      if (!status) continue;
    261299      if (xt < graphmode.xmin) continue;
     
    268306      }
    269307      if (frac <= 0.0) frac = 0.0;
    270       snprintf (format, 8, "%%.%df", (int) frac);
     308      snprintf (format, 8, "%%.%df^o", (int) frac);
    271309      snprintf (line, 16, format, d);
    272       KapaSendTextline (kapa, line, xt + dx, yt + dy, 0.0);
     310      KapaSendTextline (kapa, line, xt, yt, 0.0, JustifyDEC, LabelColor);
    273311    }
    274312  }
     
    276314  /* send the line segments as connect-points */
    277315  Xvec.Nelements = Yvec.Nelements = N;
    278   graphmode.style = 2; /* points */
    279   graphmode.ptype = 100; /* connect a pair */
     316  graphmode.style = KAPA_PLOT_POINTS; /* points */
     317  graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    280318  graphmode.etype = 0;
    281319  PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/cline.c

    r34088 r40477  
    2020
    2121  /* set point style and errorbar mode (these are NOT sticky) */
    22   graphmode.style = 0;
     22  graphmode.style = KAPA_PLOT_CONNECT;
    2323  graphmode.etype = 0;
    2424
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/czplot.c

    r35757 r40477  
    111111  Zvec.Nelements = Npts;
    112112
    113   graphmode.style = 2;
     113  graphmode.style = KAPA_PLOT_POINTS; /* points */
    114114  graphmode.size = -1; /* point size determined by Zvec */
    115115  graphmode.etype = 0;
     
    236236  Zvec.Nelements = Npts;
    237237
    238   graphmode.style = 2;
     238  graphmode.style = KAPA_PLOT_POINTS;
    239239  graphmode.color = -1; /* point color determined by Zvec */
    240240  graphmode.etype = 0;
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/fitplx.c

    r39610 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/fitplx_irls.c

    r39926 r40477  
    1212    if ((mvec = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);
    1313    remove_argument (N, &argc, argv);
    14     CastVector (mvec, OPIHI_INT);
    1514  }
    1615
     
    8180  double *dD = dDvec->elements.Flt;
    8281
    83   int *mask = NULL;
    84   if (mvec) {
    85     mask = mvec->elements.Int;
    86   }
    87 
    8882  // Ntotal : all points supplied by user
    8983  // Nsubset : unmasked points
    9084  int Ntotal = tvec->Nelements; // XXX check other lengths
    91  
     85
     86  if (rvec->Nelements  != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs ra)  = (%d vs %d)\n", rvec->Nelements, Ntotal);
     87  if (dvec->Nelements  != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dec) = (%d vs %d)\n", dvec->Nelements, Ntotal);
     88  if (dRvec->Nelements != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dR)  = (%d vs %d)\n", dRvec->Nelements, Ntotal);
     89  if (dDvec->Nelements != Ntotal) ESCAPE ("mis-match in vector lengths (mjd vs dD)  = (%d vs %d)\n", dDvec->Nelements, Ntotal);
     90 
     91  opihi_int *mask = NULL;
     92  if (mvec) {
     93    ResetVector (mvec, OPIHI_INT, Ntotal);
     94    mask = mvec->elements.Int;
     95    for (i = 0; i < Ntotal; i++) { mask[i] = 1; }
     96  }
     97
     98
    9299  double Rmean, Dmean, Tmean;
    93100  PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
     
    109116  for (i = 0; (VERBOSE == 2) && (i < fitdata.Npts); i++) {
    110117    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]);
     118    opihi_int maskValue = mask ? mask[n] : 1;
     119    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]);
    113120  }
    114121
     
    135142
    136143  // update the mask based on the input mask and the outlier limits.
    137   double Sum_Wx = 0;
    138   double Sum_Wy = 0;
    139   mask = mvec->elements.Int;
    140   for (i = 0; i < fitdata.Npts; i++) {
    141     Sum_Wx += fitdata.Wx[i];
    142     Sum_Wy += fitdata.Wy[i];
    143   }
    144   for (i = 0; i < fitdata.Npts; i++) {
    145     // fitdata only includes the previously unmasked points
    146     if ((fitdata.Wx[i] < outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))||
    147         (fitdata.Wy[i] < outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) {
    148       int n = fitdata.index[i];
    149       mask[n] = 0;
     144  if (mask) {
     145    double Sum_Wx = 0;
     146    double Sum_Wy = 0;
     147   
     148    // calculate the total weight
     149    for (i = 0; i < fitdata.Npts; i++) {
     150      Sum_Wx += fitdata.Wx[i];
     151      Sum_Wy += fitdata.Wy[i];
     152    }
     153    for (i = 0; i < fitdata.Npts; i++) {
     154      // fitdata only includes the previously unmasked points
     155      if ((fitdata.Wx[i] < outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))||
     156          (fitdata.Wy[i] < outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) {
     157        int n = fitdata.index[i];
     158        mask[n] = 0;
    150159     
    151       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);
    153       }
    154     }
    155   }
    156 
    157   if (Nresample){
    158     // now that the mask has been updated, we need to recalculate mean epoch and positions
    159     // XXX make this conditional on actually masking unmasked points above
    160     // PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
    161     // PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
     160        if (VERBOSE == 2) {
     161          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);
     162        }
     163      }
     164    }
     165  }
     166
     167  if (Nresample) {
     168    // if the mask has been updated, we need to recalculate mean epoch and positions
     169    if (mask) {
     170      PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
     171      PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
     172    }
    162173
    163174    PlxFitData sample;
     
    218229  // fprintf (stderr, "%f +/- %f | %f %f\n", fit.p, fit.dp, fit.uR, fit.uD);
    219230
    220   Vector *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
     231  Vector *dRresPOS, *dDresPOS, *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
    221232
    222233  // save fit residuals (with only pm removed, and pm and plx removed)
     234  if ((dRresPOS = SelectVector ("dRresPOS", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPOS");
     235  if ((dDresPOS = SelectVector ("dDresPOS", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPOS");
    223236  if ((dRresPMP = SelectVector ("dRresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPMP");
    224237  if ((dDresPMP = SelectVector ("dDresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPMP");
     
    226239  if ((dDresPLX = SelectVector ("dDresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPLX");
    227240   
     241  ResetVector (dRresPOS, OPIHI_FLT, Ntotal);
     242  ResetVector (dDresPOS, OPIHI_FLT, Ntotal);
    228243  ResetVector (dRresPMP, OPIHI_FLT, Ntotal);
    229244  ResetVector (dDresPMP, OPIHI_FLT, Ntotal);
     
    246261    double Yplx = fit.Do + fit.uD*t0;
    247262
     263    dRresPOS->elements.Flt[i] = x0;
     264    dDresPOS->elements.Flt[i] = y0;
    248265    dRresPMP->elements.Flt[i] = x0 - Xpmp;
    249266    dDresPMP->elements.Flt[i] = y0 - Ypmp;
     
    538555
    539556    double wx,wy;
     557    double lim_Wx = outlier_limit * Sum_Wx / (1.0 * Npts);
     558    double lim_Wy = outlier_limit * Sum_Wy / (1.0 * Npts);
    540559    for (i = 0; i < Npts; i++) {
    541       if ((Wx[i] > outlier_limit * Sum_Wx / (1.0 * Npts))||
    542           (Wy[i] > outlier_limit * Sum_Wy / (1.0 * Npts))) {
    543        
     560      int skip = (Wx[i] < lim_Wx) || (Wy[i] < lim_Wy);
     561      if (!skip) {
    544562        Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].p*pR[i];
    545563        Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].p*pD[i];
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/fitpm.c

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

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

    r39591 r40477  
    3333int imfit                   PROTO((int, char **));
    3434int imsub                   PROTO((int, char **));
     35int jdtolst                 PROTO((int, char **));
    3536int medianmap               PROTO((int, char **));
    3637int galsectors              PROTO((int, char **));
     
    103104  {1, "imfit",       imfit,        "fit function"},
    104105  {1, "imsub",       imsub,        "subtract function"},
     106  {1, "jdtolst",     jdtolst,      "JD to LST conversion"},
    105107  {1, "medianmap",   medianmap,    "small median image"},
    106108  {1, "mkgauss",     mkgauss,      "generate a 2-D gaussian centered in image"},
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.astro/star.c

    r36679 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/Makefile

    r40007 r40477  
    6666$(SRC)/hermitian1d.$(ARCH).o    \
    6767$(SRC)/hermitian2d.$(ARCH).o    \
     68$(SRC)/idxread.$(ARCH).o                \
    6869$(SRC)/imcut.$(ARCH).o          \
    6970$(SRC)/imhist.$(ARCH).o \
     
    99100$(SRC)/medimage_commands.$(ARCH).o \
    100101$(SRC)/mset.$(ARCH).o           \
    101 $(SRC)/needles.$(ARCH).o                \
     102$(SRC)/needles.$(ARCH).o        \
     103$(SRC)/nnet.$(ARCH).o           \
     104$(SRC)/nnet_commands.$(ARCH).o  \
     105$(SRC)/nnet_train.$(ARCH).o     \
     106$(SRC)/nnet_apply.$(ARCH).o     \
    102107$(SRC)/peak.$(ARCH).o           \
    103108$(SRC)/periodogram.$(ARCH).o    \
     109$(SRC)/periodogram-fm.$(ARCH).o \
    104110$(SRC)/plot.$(ARCH).o           \
    105111$(SRC)/dot.$(ARCH).o            \
     
    154160$(SRC)/type.$(ARCH).o              \
    155161$(SRC)/uniq.$(ARCH).o              \
     162$(SRC)/uniqpair.$(ARCH).o                  \
    156163$(SRC)/unsign.$(ARCH).o            \
    157164$(SRC)/vbin.$(ARCH).o              \
     
    159166$(SRC)/vclip.$(ARCH).o             \
    160167$(SRC)/vgauss.$(ARCH).o            \
     168$(SRC)/vlorentz.$(ARCH).o          \
    161169$(SRC)/vellipse.$(ARCH).o          \
    162170$(SRC)/vmaxwell.$(ARCH).o          \
     
    171179$(SRC)/vstats.$(ARCH).o            \
    172180$(SRC)/xsection.$(ARCH).o          \
    173 $(SRC)/vsh.$(ARCH).o       \
     181$(SRC)/vsh.$(ARCH).o               \
    174182$(SRC)/vshfit.$(ARCH).o    \
    175183$(SRC)/shterms.$(ARCH).o           \
     
    187195$(INC)/external.h \
    188196$(INC)/shell.h \
     197$(INC)/data.h \
    189198$(INC)/dvomath.h \
    190199$(INC)/display.h
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/dot.c

    r33963 r40477  
    2929
    3030  /* set point style and errorbar mode (these are NOT sticky) */
    31   graphmode.style = 2;
     31  graphmode.style = KAPA_PLOT_POINTS;
    3232  graphmode.etype = 0;
    3333
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/grid.c

    r34584 r40477  
    175175
    176176  Xvec.Nelements = Yvec.Nelements = N;
    177   graphmode.style = 2; /* points */
    178   graphmode.ptype = 100; /* connect a pair */
     177  graphmode.style = KAPA_PLOT_POINTS; /* points */
     178  graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    179179  graphmode.etype = 0;
    180180  PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/impeaks.c

    r36679 r40477  
    100100  int Npeaks = 0;
    101101  for (ix = 1; ix < Nx - 1; ix++) {
     102    if (!isfinite(row[ix])) continue; // ignore NAN values
    102103    if (row[ix] <  threshold) continue;   // only accept pixels above threshold
    103104    if (row[ix] <  row[ix - 1]) continue; // peak pixel must be at least preceeding pixel
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/init.c

    r40007 r40477  
    5555int hermitian1d      PROTO((int, char **));
    5656int hermitian2d      PROTO((int, char **));
     57int idxread          PROTO((int, char **));
    5758int imcut            PROTO((int, char **));
    5859int imhist           PROTO((int, char **));
     
    8990int mset             PROTO((int, char **));
    9091int needles          PROTO((int, char **));
     92int nnet_command     PROTO((int, char **));
    9193int peak             PROTO((int, char **));
    9294int periodogram      PROTO((int, char **));
     95int periodogram_fm   PROTO((int, char **));
    9396int plot             PROTO((int, char **));
    9497int dot              PROTO((int, char **));
     
    140143int tvcontour        PROTO((int, char **));
    141144int tvgrid           PROTO((int, char **));
    142 int opihi_type             PROTO((int, char **));
     145int opihi_type       PROTO((int, char **));
    143146int uniq             PROTO((int, char **));
     147int uniqpair         PROTO((int, char **));
    144148int unsign           PROTO((int, char **));
    145149int vbin             PROTO((int, char **));
     
    149153int vgrid            PROTO((int, char **));
    150154int vgauss           PROTO((int, char **));
     155int vlorentz         PROTO((int, char **));
    151156int vellipse         PROTO((int, char **));
    152157int vmaxwell         PROTO((int, char **));
     
    232237  {1, "hermitian1d",  hermitian1d,      "generate 1-D Hermitian Polynomial"},
    233238  {1, "hermitian2d",  hermitian2d,      "generate 2-D Hermitian Polynomial"},
     239  {1, "idxread",      idxread,          "read vector or image data from an IDX file"},
    234240  {1, "imbin",        rebin,            "rebin image data by factor of N"},
    235241  {1, "imclip",       imclip,           "clip values in an image to be within a range"},
     
    268274  {1, "imset",        mset,             "insert a vector in an image"},
    269275  {1, "needles",      needles,          "plot vectors needles"},
     276  {1, "nnet",         nnet_command,     "Neural Network commands"},
    270277  {1, "parity",       parity,           "set image parity"},
    271278  {1, "peak",         peak,             "find vector peak in range"},
    272   {1, "periodogram",  periodogram,      "measure periods in unevenly sampled data"},
     279  {1, "periodogram",    periodogram,    "measure periods in unevenly sampled data (Lomb-Scargle)"},
     280  {1, "periodogram_fm", periodogram_fm, "measure periods in unevenly sampled data (generalized Lomb-Scargle; floating mean)"},
    273281  {1, "plot",         plot,             "plot a pair of vectors"},
    274282  {1, "png",          jpeg,             "convert display graphic to PNG"},
     
    323331  {1, "ungridify",    ungridify,        "convert image region to vector triplet"},
    324332  {1, "uniq",         uniq,             "create a uniq vector subset from a vector"},
     333  {1, "uniqpair",     uniqpair,         "create a uniq vector subset from a pair of vectors, saving duplicates if desired"},
    325334  {1, "unsign",       unsign,           "toggle the UNSIGN status"},
    326335  {1, "vbin",         vbin,             "rebin vector data by a factor of N"},
     
    330339  {1, "vtype",        vtype,            "return the vector type (FLT or INT)"},
    331340  {1, "vgauss",       vgauss,           "fit a Gaussian to a vector"},
     341  {1, "vlorentz",     vlorentz,         "fit a Lorentzian to a vector"},
    332342  {1, "vellipse",     vellipse,         "fit a Ellipse to a vector pair"},
    333343  {1, "vgrid",        vgrid,            "generate an image from a triplet of vectors"},
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/limits.c

    r31160 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/line.c

    r33662 r40477  
    3333
    3434  /* set point style and errorbar mode (these are NOT sticky) */
    35   graphmode.style = 0;
     35  graphmode.style = KAPA_PLOT_CONNECT;
    3636  graphmode.etype = 0;
    3737
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/mslice.c

    r39233 r40477  
    33int mslice (int argc, char **argv) {
    44 
    5   int i;
     5  int N;
    66  Buffer *in, *out;
    77
     8  int Dir = 0;
     9  if ((N = get_argument (argc, argv, "-x"))) {
     10    remove_argument (N, &argc, argv);
     11    Dir = 1;   
     12  }
     13  if ((N = get_argument (argc, argv, "-y"))) {
     14    remove_argument (N, &argc, argv);
     15    if (Dir) {
     16      gprint (GP_ERR, "ERROR: multiple -x,-y,-z options are not allowed\n");
     17      return FALSE;
     18    }
     19    Dir = 2;   
     20  }
     21  if ((N = get_argument (argc, argv, "-z"))) {
     22    remove_argument (N, &argc, argv);
     23    if (Dir) {
     24      gprint (GP_ERR, "ERROR: multiple -x,-y,-z options are not allowed\n");
     25      return FALSE;
     26    }
     27    Dir = 3;   
     28  }
     29  if (!Dir) Dir = 3;
     30
    831  if (argc != 4) {
    9     gprint (GP_ERR, "USAGE: mget <input> <output> plane\n");
     32    gprint (GP_ERR, "USAGE: mslice <input> <output> plane [-x,-y,-z]\n");
     33    gprint (GP_ERR, "  -z is default\n");
    1034    return (FALSE);
    1135  }
     
    2448  int Nz = in[0].matrix.Naxis[2];
    2549
     50  int NplaneMax = 0;
     51  int Nout1 = 0;
     52  int Nout2 = 0;
     53  switch (Dir) {
     54    case 1: NplaneMax = Nx; Nout1 = Ny; Nout2 = Nz; break;
     55    case 2: NplaneMax = Ny; Nout1 = Nx; Nout2 = Nz; break;
     56    case 3: NplaneMax = Nz; Nout1 = Nx; Nout2 = Ny; break;
     57    default: myAbort ("impossible");
     58  }
     59
    2660  int invalid = FALSE;
    2761  invalid = invalid || (plane < 0);
    28   invalid = invalid || (plane >= Nz);
     62  invalid = invalid || (plane >= NplaneMax);
    2963  if (invalid) {
    30     gprint (GP_ERR, "plane %d out of range\n", plane);
     64    gprint (GP_ERR, "plane %d out of range (max = %d)\n", plane, NplaneMax);
    3165    return (FALSE);
    3266  }
    3367
    3468  /* I should encapsulate this in a create_default_buffer */
     69 
    3570  gfits_free_matrix (&out[0].matrix);
    3671  gfits_free_header (&out[0].header);
    37   if (!CreateBuffer (out, Nx, Ny, -32, 1.0, 0.0)) return FALSE;
     72  if (!CreateBuffer (out, Nout1, Nout2, -32, 1.0, 0.0)) return FALSE;
    3873
    39   float *inF  = (float *) in[0].matrix.buffer + plane*Nx*Ny;
    40   float *outF = (float *) out[0].matrix.buffer;
     74  // pixel (ix, iy, iz) : in[0].matrix.buffer + ix + iy*Nx + iz*Nx*Ny
    4175
    42   for (i = 0; i < Nx*Ny; i++, inF ++, outF++) {
    43     *outF = *inF;
     76  switch (Dir) {
     77    case 1: {
     78      float *outF = (float *) out[0].matrix.buffer;
     79     
     80      // pixel (ix, iy, iz) : in[0].matrix.buffer + ix + iy*Nx + iz*Nx*Ny
     81
     82      for (int iz = 0; iz < Nz; iz++) {
     83        float *inF  = (float *) in[0].matrix.buffer + plane + iz*Nx*Ny;
     84        for (int iy = 0; iy < Ny; iy++, inF += Nx, outF++) {
     85          *outF = *inF;
     86        }
     87      }
     88      break;
     89    }
     90    case 2: {
     91
     92      float *outF = (float *) out[0].matrix.buffer;
     93
     94      for (int iz = 0; iz < Nz; iz++) {
     95        float *inF  = (float *) in[0].matrix.buffer + plane*Nx + iz*Nx*Ny;
     96        for (int ix = 0; ix < Nx; ix++, inF++, outF++) {
     97          *outF = *inF;
     98        }
     99      }
     100      break;
     101    }
     102    case 3: {
     103      float *inF  = (float *) in[0].matrix.buffer + plane*Nx*Ny;
     104      float *outF = (float *) out[0].matrix.buffer;
     105     
     106      for (int i = 0; i < Nx*Ny; i++, inF ++, outF++) {
     107        *outF = *inF;
     108      }
     109      break;
     110    }
     111    default: myAbort ("impossible");
    44112  }
    45113  return (TRUE);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/print_vectors.c

    r37049 r40477  
    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      }
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/read_vectors.c

    r40012 r40477  
    1919  }
    2020 
     21  if (strlen(argv[1]) >= 2048) {
     22    gprint (GP_ERR, "filename %s is too long\n", argv[1]);
     23    return (FALSE);
     24  }
     25
    2126  strcpy (filename, argv[1]);
    2227  if (f != (FILE *) NULL) { fclose (f); }
    2328  f = fopen (filename, "r");
    2429  if (f == (FILE *) NULL) {
    25     gprint (GP_ERR, "failed to open file %s\n", argv[1]);
     30    gprint (GP_ERR, "failed to open file %s\n", filename);
    2631    return (FALSE);
    2732  }
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/reindex.c

    r39227 r40477  
    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++;
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/sort.c

    r20936 r40477  
    77  itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp; \
    88}
    9 # define COMPARE(A,B)(X[A] < X[B])
     9
     10// # define COMPARE(A,B)(X[A] < X[B])
     11# define COMPARE(A,B)((!isfinite(X[A]) && isfinite(X[B])) || (X[A] < X[B]))
    1012
    1113  OHANA_SORT (N, COMPARE, SWAPFUNC);
     
    2224  itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp; \
    2325}
     26
    2427# define COMPARE(A,B)(X[A] < X[B])
     28// # define COMPARE(A,B)((!isfinite(X[A]) && isfinite(X[B])) || (X[A] < X[B]))
    2529
    2630  OHANA_SORT (N, COMPARE, SWAPFUNC);
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/test/periodogram.sh

    r27435 r40477  
     1
     2if (not($?PLOT)) set PLOT = 0
    13
    24list tests
     
    2830   echo "OFFSET: {$peakpos - $P}"
    2931 end
     32
     33 if ($PLOT)
     34  lim period power; clear; box; line -c red70 -lw 3 $P 0 to $P $peakval; plot period power -x line
     35 end
    3036end
    3137
     
    107113 if (abs ($peakpos - $P) > 0.05)
    108114   $PASS = 0
     115 end
     116end
     117
     118# test using random samples, offset start, non-zero DC
     119macro test5
     120 $PASS = 1
     121 break -auto off
     122
     123 local P PI
     124 $PI = 3.14159265359
     125 $P  = 15.0
     126
     127 delete -q x t f period power
     128
     129 create x 500 800
     130 set t = 300 * rnd(x) + 500
     131 set f = sin(2*$PI*t/$P) + 0.5
     132
     133 periodogram t f 2 30 period power
     134
     135#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     136#  lim -n 1 period power; clear; box; plot period power
     137
     138 peak -q period power
     139
     140 if (abs ($peakpos - $P) > 0.05)
     141   $PASS = 0
     142 end
     143end
     144
     145# test using random samples, offset start, non-zero DC, some noise
     146macro test6
     147 $PASS = 1
     148 break -auto off
     149
     150 local P PI
     151 $PI = 3.14159265359
     152 $P  = 15.0
     153
     154 delete -q x t f period power
     155
     156 create x 500 800
     157 set t = 300 * rnd(x) + 500
     158 set fraw = sin(2*$PI*t/$P) + 0.5
     159
     160 # 0.05 : peakpos = 14.95
     161 # 0.10 : peakpos = 15.04 (
     162 gaussdev df t[] 0.0 0.25
     163 set f = fraw + df
     164
     165 periodogram t f 2 30 period power
     166
     167#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     168#  lim -n 1 period power; clear; box; plot period power
     169
     170 peak -q period power
     171
     172 if (abs ($peakpos - $P) > 0.05)
     173   $PASS = 0
     174 end
     175end
     176
     177# test using fewer random samples, offset start, non-zero DC, some noise
     178macro test7
     179 $PASS = 1
     180 break -auto off
     181
     182 local P PI
     183 $PI = 3.14159265359
     184 $P  = 15.0
     185
     186 delete -q x t f period power
     187
     188 create x 0 100
     189 set t = 100 * rnd(x)
     190 set fraw = sin(2*$PI*t/$P) + 0.5
     191
     192 # 0.05 : peakpos = 14.95
     193 # 0.10 : peakpos = 15.04 (
     194 gaussdev df t[] 0.0 0.25
     195 set f = fraw + df
     196
     197 periodogram t f 2 30 period power
     198
     199#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     200#  lim -n 1 period power; clear; box; plot period power
     201
     202 peak -q period power
     203
     204 if (abs ($peakpos - $P) > 0.05)
     205   $PASS = 0
     206 end
     207end
     208
     209# test using fewer random samples, high frequency, non-zero DC, some noise
     210macro test8
     211 if ($0 != 4)
     212   echo "USAGE: test8: Period Ndays df"
     213   break
     214 end
     215 
     216 local Ndays
     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
     226 $trueP = $P
     227
     228 delete -q x t f period power
     229
     230 create x 0 $Ndays
     231
     232 # t is a time in days, but we always have 4 within 1 hour:
     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
     236
     237 set dt1 = (15.0 / 1440) * rnd(x) + ( 0 + 7.5) / 1440
     238 set dt2 = (15.0 / 1440) * rnd(x) + (15 + 7.5) / 1440
     239 set dt3 = (15.0 / 1440) * rnd(x) + (30 + 7.5) / 1440
     240
     241 delete -q t
     242 concat t0 t
     243 set tmp = t0 + dt1; concat tmp t
     244 set tmp = t0 + dt2; concat tmp t
     245 set tmp = t0 + dt3; concat tmp t
     246
     247 set fraw = 0.75*sin(2*$PI*t/$P)
     248
     249 # 0.05 : peakpos = 14.95
     250 # 0.10 : peakpos = 15.04 (
     251 gaussdev df t[] 0.0 $dM
     252 set f = fraw + df
     253
     254 periodogram t f 0.1 2.0 period power
     255
     256#  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
     257#  lim -n 1 period power; clear; box; plot period power
     258
     259 peak -q period power
     260
     261 if (abs ($peakpos - $P) > 0.05)
     262   $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
    109266 end
    110267end
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/textline.c

    r13479 r40477  
    66  char name[64];
    77  double x, y, angle;
    8   int kapa;
    98  Graphdata graphmode;
    109
    11   if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
     10  // if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
     11
     12  // Using only these style_args options
     13  char *kapaName = NULL;
     14  int kapa = -1;
     15  if ((N = get_argument (argc, argv, "-n"))) {
     16    remove_argument (N, &argc, argv);
     17    kapaName = strcreate (argv[N]);
     18    remove_argument (N, &argc, argv);
     19  }
     20  if (!GetGraph (&graphmode, &kapa, kapaName)) return (FALSE);
     21  FREE (kapaName);
     22
     23  int color = KapaColorByName ("black");
     24  if ((N = get_argument (argc, argv, "-c"))) {
     25    remove_argument (N, &argc, argv);
     26    color = KapaColorByName (argv[N]);
     27    if (color == -1) return (FALSE);
     28    remove_argument (N, &argc, argv);
     29  }
    1230
    1331  if ((N = get_argument (argc, argv, "-fn"))) {
     
    3452  }
    3553
     54  int justify = 5; // default
     55  if ((N = get_argument (argc, argv, "-justify"))) {
     56    remove_argument (N, &argc, argv);
     57    justify = atoi (argv[N]);
     58    remove_argument (N, &argc, argv);
     59  }
     60
    3661  if (argc != 4) {
    37     gprint (GP_ERR, "USAGE: text x y (line) [-fn (font) size] [-rot angle]\n");
     62    gprint (GP_ERR, "USAGE: text x y (line) [-fn (font) size] [-rot angle] [-justify N]\n");
    3863    return (FALSE);
    3964  }
     
    5277  }   
    5378
    54   KapaSendTextline (kapa, argv[3], x, y, angle);
     79  KapaSendTextline (kapa, argv[3], x, y, angle, justify, color);
    5580  return (TRUE);
    5681}
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/uniq.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/write_vectors.c

    r39360 r40477  
    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        }
  • branches/czw_branch/20170908/Ohana/src/opihi/cmd.data/zplot.c

    r38062 r40477  
    117117
    118118  /* point size determined by Zvec */
    119   graphmode.style = 2; /* plot points */
     119  graphmode.style = KAPA_PLOT_POINTS; /* points */
    120120  graphmode.size = -1; /* point size determined by Zvec */
    121121  PlotVectorTriplet (kapa, xvec, yvec, &Zvec, mask, &graphmode);
     
    226226
    227227  /* point size determined by Zvec */
    228   graphmode.style = 2; /* plot points */
     228  graphmode.style = KAPA_PLOT_POINTS; /* plot points */
    229229  graphmode.color = -1; /* point color determined by Zvec */
    230230  graphmode.etype = 0; /* no errorbars */
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/Makefile

    r39602 r40477  
    2727$(SRC)/mySequence.$(ARCH).o             \
    2828$(SRC)/photcode_ops.$(ARCH).o           \
     29$(SRC)/PeriodogramOps.$(ARCH).o         \
    2930$(SRC)/find_matches.$(ARCH).o           
    3031
     
    4546$(SRC)/avextract.$(ARCH).o              \
    4647$(SRC)/avmatch.$(ARCH).o                \
     48$(SRC)/avperiodogram.$(ARCH).o          \
     49$(SRC)/avperiodomatch.$(ARCH).o         \
    4750$(SRC)/badimages.$(ARCH).o              \
    4851$(SRC)/catdir.$(ARCH).o                 \
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/catalog.c

    r38471 r40477  
    390390    REALLOCATE (Zvec.elements, float, MAX (Zvec.Nelements, 1));
    391391   
    392     graphmode.style = 2; /* set style to points */
     392    graphmode.style = KAPA_PLOT_POINTS; /* points */
    393393    graphmode.size = -1; /* point size determined by Zvec */
    394394    graphmode.etype = 0; /* no errorbars */
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/dmt.c

    r39457 r40477  
    150150    vec5[0].Nelements = Dvec.Nelements;
    151151  } else {
    152     graphmode.style = 2; /* set style to points */
     152    graphmode.style = KAPA_PLOT_POINTS; /* points */
    153153    PlotVector (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    154154
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/dvo_host_utils.c

    r39524 r40477  
    212212        continue;
    213213      }
    214       free (table->hosts[i].results);
    215       table->hosts[i].results = NULL;
     214      // free (table->hosts[i].results);
     215      // table->hosts[i].results = NULL;
    216216      set_int_variable (name, 1); // result file has been read
    217217
     
    225225        FreeVectorArray (invec, Ninvec);
    226226      }
     227    } else {
     228      // free (table->hosts[i].results);
     229      // table->hosts[i].results = NULL;
    227230    }
    228231  }
     
    242245  free (vec);
    243246
    244   free (table);
     247  FreeHostTable (table);
    245248  return TRUE;
    246249}
     
    284287    // XXX a bit of a waste (but only 1024 * 60 bytes or so
    285288    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);
     289    snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.%04d.fits", table->hosts[i].pathname, uniquer, table->hosts[i].hostID);
    287290
    288291    int    Ninvec = 0;
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/fitcolors.c

    r39457 r40477  
    4848  if (!SetPhotSelections (&argc, argv, 4)) goto usage;
    4949
     50  int textcolor = KapaColorByName ("black");
     51
    5052  // range for valid data points (exclude extreme outliers)
    5153  minDelta = -0.2;
     
    9294    graphdata.ymin = minDelta;
    9395    graphdata.ymax = maxDelta;
    94     graphdata.style = 2;
    95     graphdata.ptype = 2;
     96    graphmode.style = KAPA_PLOT_POINTS; /* points */
     97    graphmode.ptype = KAPA_POINT_CIRCLE_SOLID; /* connect pairs of points */
    9698    KapaClearSections (kapa);
    9799    KapaSetFont (kapa, "helvetica", 14);
     
    192194    graphdata.ymin = minDelta;
    193195    graphdata.ymax = maxDelta;
    194     graphdata.style = 2;
    195     graphdata.ptype = 2;
     196    graphmode.style = KAPA_PLOT_POINTS; /* points */
     197    graphmode.ptype = KAPA_POINT_CIRCLE_SOLID; /* connect pairs of points */
    196198  }
    197199
     
    315317          deltaFit[i] = C0 + C1*colorFit[i];
    316318        }
    317         graphdata.style = 0;
     319        graphmode.style = KAPA_PLOT_CONNECT; /* lines */
    318320        graphdata.color = KapaColorByName ("red");
    319321
     
    324326        KapaSetFont (kapa, "helvetica", 8);
    325327        sprintf (label, "%s", code[0][0].name);
    326         KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0);
     328        KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0, textcolor);
    327329        sprintf (label, "%s", code[1][0].name);
    328         KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0);
     330        KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0, textcolor);
    329331        KapaSetFont (kapa, "helvetica", 14);
    330332
    331         graphdata.style = 2;
     333        graphmode.style = KAPA_PLOT_POINTS; /* points */
    332334        graphdata.color = KapaColorByName ("black");
    333335
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/fitsed.c

    r39457 r40477  
    157157    if (!GetGraph (&graphdata, &kapa, NULL)) return (FALSE);
    158158    SetLimitsRaw (wavecode, NULL, Nfilter, &graphdata);
    159     graphdata.style = 2;
    160     graphdata.ptype = 2;
     159    graphdata.style = KAPA_PLOT_POINTS; /* points */
     160    graphdata.ptype = KAPA_POINT_CIRCLE_SOLID;
    161161    KapaClearSections (kapa);
    162162    magSection.name = strcreate ("mag");
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/gimages.c

    r39347 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/gstar.c

    r39634 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/images.c

    r37807 r40477  
    352352  Xvec.Nelements = Yvec.Nelements = N;
    353353  if (N > 0) {
    354     graphmode.style = 2; /* points */
    355     graphmode.ptype = 100; /* connect pairs of points */
     354    graphmode.style = KAPA_PLOT_POINTS; /* points */
     355    graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    356356    graphmode.etype = 0;
    357357    PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imbox.c

    r39926 r40477  
    156156  Xvec.Nelements = Yvec.Nelements = Npts;
    157157  if (Npts > 0) {
    158     graphmode.style = 2; /* points */
    159     graphmode.ptype = 100; /* connect pairs of points */
     158    graphmode.style = KAPA_PLOT_POINTS; /* points */
     159    graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    160160    graphmode.etype = 0;
    161161    PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imdata.c

    r39457 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imdense.c

    r39926 r40477  
    5959  Xvec.Nelements = Yvec.Nelements = N;
    6060  if (N > 0) {
    61     graphmode.style = 2; /* points */
     61    graphmode.style = KAPA_PLOT_POINTS; /* points */
    6262    graphmode.etype = 0;
    6363    PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imlist.c

    r39310 r40477  
    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) {
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imphot.c

    r39233 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/imstats.c

    r37807 r40477  
    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);
    5252
    53   graphmode.style = 2;
     53  graphmode.style = KAPA_PLOT_POINTS; /* points */
    5454  graphmode.etype = 0;
    5555  PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/init.c

    r39602 r40477  
    33int avextract       PROTO((int, char **));
    44int avmatch         PROTO((int, char **));
     5int avperiodogram   PROTO((int, char **));
     6int avperiodomatch  PROTO((int, char **));
    57int badimages       PROTO((int, char **));
    68int calextract      PROTO((int, char **));
     
    6769  {1, "avextract",   avextract,    "extract average data values"},
    6870  {1, "avmatch",     avmatch,      "extract average data values matched to RA,DEC points"},
     71  {1, "avperiodogram",  avperiodogram, "perform periodogram on objects based on restrictions"},
     72  {1, "avperiodomatch", avperiodomatch, "perform periodogram on objects based on ra,dec list"},
    6973  {1, "badimages",   badimages,    "look for images with anomalous astrometry"},
    7074//  {1, "calextract",  calextract,   "extract photometry calibration"},
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/objectcoverage.c

    r39457 r40477  
    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       
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/paverage.c

    r39457 r40477  
    8181    return (FALSE);
    8282  }
    83   graphmode.style = 2; /* set style to points */
     83  graphmode.style = KAPA_PLOT_POINTS; /* points */
    8484  graphmode.size = -1; /* point size determined by Zvec */
    8585  graphmode.etype = 0; /* no errorbars */
     
    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;
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/pmeasure.c

    r39457 r40477  
    154154    return (FALSE);
    155155  }
    156   graphmode.style = 2; /* set style to points */
     156  graphmode.style = KAPA_PLOT_POINTS; /* points */
    157157  graphmode.size = -1; /* point size determined by Zvec */
    158158  graphmode.etype = 0; /* no errorbars */
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/procks.c

    r39457 r40477  
    111111  Yvec.Nelements = Xvec.Nelements = N;
    112112 
    113   graphmode.style = 2; /* set style to points */
     113  graphmode.style = KAPA_PLOT_POINTS; /* points */
    114114  graphmode.etype = 0; /* no errorbars */
    115115  PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
     
    142142  Yvec.Nelements = Xvec.Nelements = N;
    143143 
    144   graphmode.style = 2; /* set style to points */
    145   graphmode.ptype = 100; /* connect pairs */
     144  graphmode.style = KAPA_PLOT_POINTS; /* points */
     145  graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    146146  graphmode.etype = 0; /* no errorbars */
    147147
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/region_list.c

    r33662 r40477  
    181181  SkyList *skylist;
    182182
     183  // the list of regions comes directly from a file
     184  if (selection->list != NULL) {
     185    skylist = SkyListLoadFile (selection->list);
     186    return (skylist);
     187  }
     188
     189  // all other options require sky to be set
     190  if (!sky) {
     191    gprint (GP_ERR, "CATDIR not set\n");
     192    return NULL;
     193  }
     194
    183195  /* determine region-file names */
    184196  if (selection->name != NULL) {
     
    186198    return (skylist);
    187199  }
    188 
    189   if (selection->list != NULL) {
    190     skylist = SkyListLoadFile (selection->list);
    191     return (skylist);
    192   }
    193200
    194201  if (selection->useDisplay) {
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/remote.c

    r39283 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/showtile.c

    r39457 r40477  
    7878  Xvec.Nelements = Yvec.Nelements = N;
    7979  if (N > 0) {
    80     graphmode.style = 2; /* points */
    81     graphmode.ptype = 100; /* connect pairs of points */
     80    graphmode.style = KAPA_PLOT_POINTS; /* points */
     81    graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    8282    graphmode.etype = 0;
    8383    PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/simage.c

    r37807 r40477  
    118118  }
    119119
    120   graphmode.style = 2;
     120  graphmode.style = KAPA_PLOT_POINTS;
    121121  graphmode.size = -1;
    122122  graphmode.etype = 0;
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/skycat.c

    r39926 r40477  
    121121  Xvec.Nelements = Yvec.Nelements = Npts;
    122122  if (Npts > 0) {
    123     graphmode.style = 2; /* points */
    124     graphmode.ptype = 100; /* connect pairs of points */
     123    graphmode.style = KAPA_PLOT_POINTS; /* points */
     124    graphmode.ptype = KAPA_POINT_PAIR_CONNECT; /* connect pairs of points */
    125125    graphmode.etype = 0;
    126126    PlotVectorPair (kapa, &Xvec, &Yvec, NULL, &graphmode);
  • branches/czw_branch/20170908/Ohana/src/opihi/dvo/skycoverage.c

    r39233 r40477  
    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: {
  • branches/czw_branch/20170908/Ohana/src/opihi/include/astro.h

    r39610 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/include/data.h

    r37807 r40477  
    5050  float **buffers;
    5151} MedImageType;
     52
     53/*** typedef structs used by the Neural Network functions (nnet_*) ***/
     54typedef struct {
     55  char *name;
     56  int Nlayer; // Nlayers = input layer + output layer + hidden layers
     57  int *Nnodes; // number of nodes per layer
     58  float **weight; // a matrix between each layer
     59  float **biases; // a vector for each layer
     60
     61  float **zvalue; // a vector of z values for each layer (= w*input + b)
     62  float **svalue; // a vector of s values for each layer (= sigmoid(z))
     63  float **sprime; //
     64  float **delta;  //
     65
     66  float ** Nabla_b; // a vector of Nabla_b values for each layer
     67  float **dNabla_b; // a vector of Nabla_b values for each layer
     68
     69  float ** Nabla_w; // a matrix of Nabla_w values for each layer
     70  float **dNabla_w; // a matrix of Nabla_w values for each layer
     71} Nnet;
    5272
    5373void InitData (void);
     
    162182/* starfuncs.c */
    163183double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE);
     184double get_box_stats (Matrix *matrix, int X, int Y, int dX, int dY, int Nborder, double max, int VERBOSE);
     185
    164186int set_rough_radii (double Ra, double Ri, double Ro);
    165187int 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);
     
    227249int GetKapaChannelFromString (char *string);
    228250
     251/*** Neural Network functions (nnet_*) ***/
     252
     253// in lib.data/nnet.c:
     254void InitNnets ();
     255void InitNnetData (Nnet *nnet, char *name, int Nlayer);
     256
     257void FreeNnets ();
     258void FreeNnetData (Nnet *nnet);
     259
     260Nnet *GetNnet (int where);
     261Nnet *FindNnet (char *name);
     262Nnet *CreateNnet (char *name, int Nlayer);
     263void CreateNnetData (Nnet *nnet, int LargeWeightInit);
     264
     265void PrintNnet (Nnet *nnet);
     266int  DeleteNnet (Nnet *nnet);
     267void ListNnets ();
     268
     269// in cmd.data/nnet.c:
     270int nnet_command (int argc, char **argv);
     271
     272// in cmd.data/nnet_commands.c:
     273int nnet_init (int argc, char **argv);
     274int nnet_list (int argc, char **argv);
     275int nnet_delete (int argc, char **argv);
     276int nnet_create (int argc, char **argv);
     277int nnet_set (int argc, char **argv);
     278int nnet_get (int argc, char **argv);
     279int nnet_read (int argc, char **argv);
     280int nnet_write (int argc, char **argv);
     281int nnet_print (int argc, char **argv);
     282
     283// in cmd.data/nnet_train.c:
     284int nnet_train (int argc, char **argv);
     285void nnet_feedforward (Nnet *nnet);
     286
     287// in cmd.data/nnet_apply.c:
     288int nnet_apply (int argc, char **argv);
     289
    229290# endif
  • branches/czw_branch/20170908/Ohana/src/opihi/include/dvoshell.h

    r39569 r40477  
    4141char *HOSTDIR;
    4242char *RESULT_FILE;
     43
     44typedef struct {
     45  int Nmeasure;
     46  int Nperiods;
     47  opihi_flt *period;
     48  opihi_flt *power;
     49  double P50;
     50  double R50;
     51  double R90;
     52} PeriodogramResult;
     53
     54/*** Periodogram functions (avperiodogram and avperiodomatch) ***/
     55void PeriodogramResultFree (PeriodogramResult *result);
     56void PeriodogramResultSave (PeriodogramResult *result, char *extname, FILE *foutput, Average *average);
     57void PeriodogramSetOptions (float minimumPeriod, float maximumPeriod);
     58PeriodogramResult *PeriodogramRawFloatingMean (opihi_flt *time, opihi_flt *flux, opihi_flt *dflux, int Npts);
    4359
    4460/*** dvo prototypes ***/
  • branches/czw_branch/20170908/Ohana/src/opihi/include/pantasks.h

    r36623 r40477  
    88
    99# define DEBUG 0
     10
     11typedef int IDtype;
    1012
    1113typedef enum {
     
    133135 
    134136typedef struct {
    135   int JobID;                            /* internal ID for job */
     137  IDtype JobID;                         /* internal ID for job */
    136138  int pid;                              /* external ID for job */
    137139
     
    204206void UpdateTaskTimerStats (Task *task, int mode, double dtime);
    205207
    206 int NextJobID (void);
     208IDtype NextJobID (void);
    207209void InitJobIDs (void);
    208210void FreeJobIDs (void);
    209 int FreeJobID (int ID);
    210211
    211212void InitJobs (void);
     
    213214
    214215Job *NextJob (void);
    215 Job *FindJob (int JobID);
     216Job *FindJob (IDtype JobID);
    216217void ListJobs (void);
    217218Job *CreateJob (Task *task);
     
    234235int SubmitControllerJob (Job *job);
    235236int DeleteControllerJob (Job *job);
    236 Job *FindControllerJob (int JobID);
     237Job *FindControllerJob (IDtype JobID);
    237238int StartController (void);
    238239int ControllerCommand (char *command, char *response, IOBuffer *buffer);
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.data/Makefile

    r39242 r40477  
    2020$(SDIR)/fft.$(ARCH).o                   \
    2121$(SDIR)/svdcmp.$(ARCH).o                \
    22 $(SDIR)/svdcmp_bond_new.$(ARCH).o               \
     22$(SDIR)/svdcmp_bond_new.$(ARCH).o       \
    2323$(SDIR)/bracket.$(ARCH).o               \
    2424$(SDIR)/spline.$(ARCH).o                \
     
    2727$(SDIR)/mrqmin.$(ARCH).o                \
    2828$(SDIR)/mrq2dmin.$(ARCH).o              \
     29$(SDIR)/nnet.$(ARCH).o                  \
    2930$(SDIR)/precess.$(ARCH).o               \
    3031$(SDIR)/starfuncs.$(ARCH).o             \
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.data/gaussian.c

    r38986 r40477  
    2626  if (Ngaussint == Nbin) return;
    2727
    28   long A = time(NULL);
    29   srand48(A);
     28  // long A = time(NULL);
     29  // srand48() is called by startup
    3030 
    3131  Ngaussint = Nbin;
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.data/graphtools.c

    r38153 r40477  
    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++) {
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.data/starfuncs.c

    r36679 r40477  
    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;
     
    171285    off = j*Nx;
    172286    for (i = Xs; i < Xe; i++) {
     287      if (!isfinite(data[i+off])) continue;
    173288      sky[Nsky] = data[i+off];
    174289      Nsky ++;
     
    180295    off = j*Nx;
    181296    for (i = Xs; i < Xe; i++) {
     297      if (!isfinite(data[i+off])) continue;
    182298      sky[Nsky] = data[i+off];
    183299      Nsky ++;
     
    191307    off = j*Nx;
    192308    for (i = Xs; i < Xe; i++) {
     309      if (!isfinite(data[i+off])) continue;
    193310      sky[Nsky] = data[i+off];
    194311      Nsky ++;
     
    200317    off = j*Nx;
    201318    for (i = Xs; i < Xe; i++) {
     319      if (!isfinite(data[i+off])) continue;
    202320      sky[Nsky] = data[i+off];
    203321      Nsky ++;
     
    227345      rad2 = SQ(Xc) + SQ(Yc);
    228346      if (rad2 > Ro2) continue;
     347      // if (!isfinite(data[i+off])) continue;
    229348      value = data[i+off] - fsky;
    230349      Sx  += Xc*value;
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/VectorIO.c

    r39457 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/check_stack.c

    r38062 r40477  
    4848          Nz = stack[i].buffer[0].matrix.Naxis[2];
    4949        }
    50         if ((Nx != stack[i].buffer[0].matrix.Naxis[0]) &&
    51             (Ny != stack[i].buffer[0].matrix.Naxis[1]) &&
     50        if ((Nx != stack[i].buffer[0].matrix.Naxis[0]) ||
     51            (Ny != stack[i].buffer[0].matrix.Naxis[1]) |
    5252            (Nz != stack[i].buffer[0].matrix.Naxis[2])) {
    5353          push_error ("dimensions don't match");
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r39558 r40477  
    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 */
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/dvomath.c

    r39457 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r40207 r40477  
    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);
     
    186186      got_two_op:
    187187        if (!status) {
    188           snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
     188          // we are guaranteed to have stack[i-1] and stack[i-2] since i >= 2 (above)
     189          char tmpvector[] = "Temporary Vector";
     190          char tmpmatrix[] = "Temporary Matrix";
     191         
     192          char *name1 = NULL;
     193          if (stack[i-1].name) {
     194            name1 = stack[i-1].name;
     195          } else {
     196            if (stack[i-1].type == ST_VECTOR_TMP) name1 = tmpvector;
     197            if (stack[i-1].type == ST_MATRIX_TMP) name1 = tmpmatrix;
     198          }
     199          char *name2 = NULL;
     200          if (stack[i-2].name) {
     201            name2 = stack[i-2].name;
     202          } else {
     203            if (stack[i-2].type == ST_VECTOR_TMP) name2 = tmpvector;
     204            if (stack[i-2].type == ST_MATRIX_TMP) name2 = tmpmatrix;
     205          }
     206
     207          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", name1, name2);
    189208          push_error (line);
     209
    190210          int isTrinary = TRUE;
    191211          isTrinary = isTrinary && (i >= 2);
     
    199219            push_error (line);
    200220          }
     221
    201222          clear_stack (&tmp_stack);
    202223          return (FALSE);
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/parse.c

    r33662 r40477  
    145145    /* simple variable assignment */
    146146    /* dvomath returns a new string, or NULL, with the result of the expression */
     147    /* if dvomath returns NULL, the expression was not a math operation: treat as a string */
    147148    val = dvomath (1, &V1, &size, 0);
    148149    if (val == NULL) {
    149150      while (OHANA_WHITESPACE (*V1)) V1++;
    150151      val = strcreate (V1);
     152      init_error ();
    151153    }
    152154    // save the result
     
    245247        vec[0].elements.Flt[Nx] = atof (val);
    246248      } else {
    247         vec[0].elements.Int[Nx] = atol (val);
     249        vec[0].elements.Int[Nx] = atoll (val);
    248250      }
    249251    }
  • branches/czw_branch/20170908/Ohana/src/opihi/lib.shell/stack_math.c

    r40019 r40477  
    599599}
    600600
    601 // the vector is applied to each column (currently only valid for 2D matrix)
     601// the vector is applied to each ROW (currently only valid for 2D matrix), e.g.: M[20,10] * X[20] -> M'[20,10] where M'[2,1] = M[2,1] * X[2]
    602602int MV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
    603603
     
    607607  Nx = V1[0].buffer[0].matrix.Naxis[0];
    608608  Ny = V1[0].buffer[0].matrix.Naxis[1];
    609   if (Ny != V2[0].vector[0].Nelements) {
    610     push_error ("dimension mismatch");
     609  if (Nx != V2[0].vector[0].Nelements) {
     610    snprintf (line, 512, "error: matrix OP vector matrix dimensions do not match: (%d x %d) OP %d", Nx, Ny, V2[0].vector[0].Nelements);
     611    push_error (line);
    611612    return (FALSE);
    612613  }
     
    628629# define MV_FUNC(OP) {                                  \
    629630    if (V2->vector->type == OPIHI_FLT) {                \
    630       opihi_flt *M2  =  V2[0].vector[0].elements.Flt;   \
    631       for (i = 0; i < Ny; i++, M2++) {                  \
    632         for (j = 0; j < Nx; j++, out++, M1++) {         \
     631      for (i = 0; i < Ny; i++) {                        \
     632        opihi_flt *M2  =  V2[0].vector[0].elements.Flt; \
     633        for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
    633634          *out = OP;                                    \
    634635        }                                               \
     
    637638    }                                                   \
    638639    if (V2->vector->type != OPIHI_FLT) {                \
    639       opihi_int *M2  =  V2[0].vector[0].elements.Int;   \
    640       for (i = 0; i < Ny; i++, M2++) {                  \
    641         for (j = 0; j < Nx; j++, out++, M1++) {         \
     640      for (i = 0; i < Ny; i++) {                        \
     641        opihi_int *M2  =  V2[0].vector[0].elements.Int; \
     642        for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
    642643          *out = OP;                                    \
    643644        }                                               \
     
    695696}
    696697
    697 // the vector is applied to each row (currently only valid for 2D matrix)
     698// the vector is applied to each COLUMN (currently only valid for 2D matrix)
     699// e.g.: X[10] * M[20,10] -> M'[20,10] where M'[2,1] = X[1] * M[2,1]
    698700int VM_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
    699701
     
    703705  Nx = V2[0].buffer[0].matrix.Naxis[0];
    704706  Ny = V2[0].buffer[0].matrix.Naxis[1];
    705   if (Nx != V1[0].vector[0].Nelements) {
     707  if (Ny != V1[0].vector[0].Nelements) {
     708    snprintf (line, 512, "error: vector OP matrix dimensions do not match: %d OP (%d x %d)", V1[0].vector[0].Nelements, Nx, Ny);
     709    push_error (line);
    706710    return (FALSE);
    707711  }
     
    722726# define VM_FUNC(OP) {                                  \
    723727    if (V1->vector->type == OPIHI_FLT) {                \
    724       for (i = 0; i < Ny; i++) {                        \
    725         opihi_flt *M1  = V1[0].vector[0].elements.Flt;  \
    726         for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
     728      opihi_flt *M1  = V1[0].vector[0].elements.Flt;    \
     729      for (i = 0; i < Ny; i++, M1++) {                  \
     730        for (j = 0; j < Nx; j++, out++, M2++) { \
    727731          *out = OP;                                    \
    728732        }                                               \
     
    731735    }                                                   \
    732736    if (V1->vector->type != OPIHI_FLT) {                \
    733       for (i = 0; i < Ny; i++) {                        \
    734         opihi_int *M1  =  V1[0].vector[0].elements.Int; \
    735         for (j = 0; j < Nx; j++, out++, M1++, M2++) {   \
     737      opihi_int *M1  =  V1[0].vector[0].elements.Int;   \
     738      for (i = 0; i < Ny; i++, M1++) {                  \
     739        for (j = 0; j < Nx; j++, out++, M2++) { \
    736740          *out = OP;                                    \
    737741        }                                               \
  • branches/czw_branch/20170908/Ohana/src/opihi/mana/findrowpeaks.c

    r2938 r40477  
    2323
    2424  for (i = 1; i < Nrow - 1; i++) {
     25    if (!isfinite(row[i])) continue; // ignore NAN values
    2526    if (row[i] < threshold) continue;
    2627    if (row[i] < row[i-1]) continue;
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/CheckController.c

    r39476 r40477  
    77
    88  char *p, *q;
    9   int i, Njobs, status, JobID;
     9  int i, Njobs, status;
     10  IDtype JobID;
    1011  Job *job;
    1112  IOBuffer buffer;
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/JobIDOps.c

    r23557 r40477  
    11# include "pantasks.h"
    22
    3 # define MAX_N_JOBS 10000
    4 static char *JobIDList;
    5 static int   JobIDPtr;
     3# define MAX_N_JOBS 0x80000000
     4
     5static IDtype JobIDMax = 0;
    66
    77void InitJobIDs () {
    8 
    9   JobIDPtr = 0;
    10   ALLOCATE (JobIDList, char, MAX_N_JOBS);
    11   bzero (JobIDList, MAX_N_JOBS*sizeof(char));
     8  JobIDMax = 0;
    129
    1310
    14 void FreeJobIDs () {
    15   free (JobIDList);
     11void FreeJobIDs () { }
     12
     13/* return next unique ID, recycle every MAX_N_JOBS */
     14IDtype NextJobID () {
     15
     16  JobIDMax ++;
     17  if (JobIDMax >= MAX_N_JOBS) {
     18    gprint (GP_ERR, "ERROR: too many jobs spawned: %d, aborting\n", JobIDMax);
     19    abort();
     20  }
     21
     22  return (JobIDMax);
    1623}
    1724
    18 /* return next unique ID, recycle every MAX_N_JOBS */
    19 int NextJobID () {
    20 
    21   int Ntry;
    22 
    23   JobIDPtr ++;
    24   if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;
    25 
    26   Ntry = 0;
    27   while (JobIDList[JobIDPtr]) {
    28     Ntry ++;
    29     JobIDPtr ++;
    30     if (JobIDPtr >= MAX_N_JOBS) JobIDPtr = 0;
    31     if (Ntry == MAX_N_JOBS) return (-1);
    32   }
    33   JobIDList[JobIDPtr] = TRUE;
    34   return (JobIDPtr);
    35 }
    36 
    37 int FreeJobID (int JobID) {
    38 
    39   if (JobID < 0) return (FALSE);
    40   if (JobID >= MAX_N_JOBS) return (FALSE);
    41 
    42   JobIDList[JobID] = FALSE;
    43   return (TRUE);
    44 }
     25/* I am going to rework the jobID so that it just grows.  no need to ever free them
     26   as an int, that allows 2^31 jobs (2e9 jobs) */
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/JobOps.c

    r38559 r40477  
    4141
    4242/* return job with given ID */
    43 Job *FindJob (int JobID) {
     43Job *FindJob (IDtype JobID) {
    4444
    4545  int i;
     
    5555
    5656/* return job with given controller Job ID */
    57 Job *FindControllerJob (int JobID) {
     57Job *FindControllerJob (IDtype JobID) {
    5858
    5959  int i;
     
    8282  gprint (GP_LOG, " Jobs in Pantasks Queue\n");
    8383  for (i = 0; i < Njobs; i++) {
    84     gprint (GP_LOG, " %4d  %6d: %-25s %10s %20s\n", Njobs, jobs[i][0].JobID, jobs[i][0].task[0].name, JobStateToString(jobs[i][0].state), jobs[i][0].argv[0]);
     84    gprint (GP_LOG, " %4d  %8d: %-25s %10s %20s\n", Njobs, jobs[i][0].JobID, jobs[i][0].task[0].name, JobStateToString(jobs[i][0].state), jobs[i][0].argv[0]);
    8585  }
    8686
     
    9797
    9898  job[0].JobID = NextJobID ();
     99
     100  // this should not happen; abort?
    99101  if (job[0].JobID < 0) {
    100102    free (job);
     
    165167  if (job == NULL) return;
    166168 
    167   FreeJobID (job[0].JobID);
    168 
    169169  for (i = 0; i < job[0].argc; i++) {
    170170    free (job[0].argv[i]);
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/delete.c

    r23530 r40477  
    44
    55  Job *job;
    6   int JobID;
     6  IDtype JobID;
    77
    88  if (argc != 3) goto usage;
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/kill.c

    r23530 r40477  
    44
    55  Job *job;
    6   int JobID;
     6  IDtype JobID;
    77
    88  if (argc < 2) {
     
    1010    return (FALSE);
    1111  }
    12   JobID = atoi (argv[1]);
     12  JobID = atoll (argv[1]);
    1313
    1414  JobTaskLock();
  • branches/czw_branch/20170908/Ohana/src/opihi/pantasks/test/nice_remote.sh

    r32632 r40477  
    1010  periods      -timeout 20
    1111  active       true
    12   npending 5
     12  npending 50
    1313 
    1414  stdout tmp.txt
     
    4444  periods      -timeout 20
    4545  active       true
    46   npending 5
     46  npending 50
    4747 
    4848  stdout tmp.txt
  • branches/czw_branch/20170908/Ohana/src/photdbc/src/get_mags.c

    r37045 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/photdbc/src/join_stars.c

    r38441 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/photdbc/src/make_subcatalog.c

    r39926 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/relastro/Makefile

    r39693 r40477  
    1 default: relastro relastro_client fitobj fitobj2 fitobj3 fitpm
     1default: relastro relastro_client fitobj fitobj2 fitobj3 fitexample
    22help:
    33        @echo "make options: relastro (default)"
     
    109109$(SRC)/relastroVisual.$(ARCH).o
    110110
    111 #$(SRC)/write_coords.$(ARCH).o        \
     111#$(SRC)/write_coords.$(ARCH).o       
     112#$(SRC)/UpdateStacksWithFit.$(ARCH).o
    112113
    113114$(RELASTRO): $(INC)/relastro.h
     
    187188$(BIN)/testparallax.$(ARCH): $(TESTPAR)
    188189
    189 fitpm: $(BIN)/fitpm.$(ARCH)
    190 
    191 FITPM = \
    192 $(SRC)/fitpm.$(ARCH).o        \
    193 $(SRC)/ParFactor.$(ARCH).o           \
    194 $(SRC)/FitAstromOps.$(ARCH).o        \
    195 $(SRC)/FitPosPMfixed.$(ARCH).o               \
    196 $(SRC)/FitPM.$(ARCH).o               \
    197 $(SRC)/FitPMandPar.$(ARCH).o               \
    198 $(SRC)/FitPosStack.$(ARCH).o       \
    199 $(SRC)/BootstrapOps.$(ARCH).o        \
    200 $(SRC)/mkpolyterm.$(ARCH).o            \
    201 $(SRC)/fitpoly.$(ARCH).o
    202 
    203 $(FITPM): $(INC)/relastro.h
    204 $(BIN)/fitpm.$(ARCH): $(FITPM)
     190fitexample: $(BIN)/fitexample.$(ARCH)
     191
     192FITEXAMPLE = \
     193$(SRC)/fitexample.$(ARCH).o           \
     194$(SRC)/ParFactor.$(ARCH).o           \
     195$(SRC)/FitAstromOps.$(ARCH).o        \
     196$(SRC)/FitPosPMfixed.$(ARCH).o               \
     197$(SRC)/FitPM.$(ARCH).o               \
     198$(SRC)/FitPMandPar.$(ARCH).o               \
     199$(SRC)/FitPosStack.$(ARCH).o       \
     200$(SRC)/BootstrapOps.$(ARCH).o        \
     201$(SRC)/mkpolyterm.$(ARCH).o            \
     202$(SRC)/fitpoly.$(ARCH).o
     203
     204$(FITEXAMPLE): $(INC)/relastro.h
     205$(BIN)/fitexample.$(ARCH): $(FITEXAMPLE)
    205206
    206207fitobj: $(BIN)/fitobj.$(ARCH)
  • branches/czw_branch/20170908/Ohana/src/relastro/include/relastro.h

    r39926 r40477  
    3333typedef enum {OP_NONE, OP_IMAGES, OP_HIGH_SPEED, OP_MERGE_SOURCE, OP_UPDATE_OBJECTS, OP_UPDATE_OFFSETS, OP_LOAD_OBJECTS, OP_HPM, OP_PARALLEL_REGIONS, OP_PARALLEL_IMAGES, OP_REPAIR_STACKS, OP_REPAIR_WARPS, OP_REPAIR_OBJECT_ID} RelastroOp;
    3434
    35 typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, SET_CHIPS, TARGET_MOSAICS} FitTarget;
     35typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, SET_CHIPS, SET_STACKS, TARGET_MOSAICS} FitTarget;
    3636
    3737typedef enum {
     
    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;
     
    366367int    USE_ICRF_POLE;
    367368
     369int    FIT_STACKS;
     370int    IMSTATS_ONLY;
    368371int    REPAIR_STACKS;
    369372int    USE_IMAGE_COORDS_FOR_REPAIR;
     
    377380int    SKIP_CFH;
    378381
     382int    UPDATE_ALL_MEASURE;
    379383int    UPDATE_PS1_STACK_MEASURE;
    380384int    UPDATE_PS1_CHIP_MEASURE;
     
    621625int UpdateChips (Catalog *catalog, int Ncatalog, int Nloop);
    622626int UpdateStacks (Catalog *catalog, int Ncatalog);
     627int UpdateStacksWithFit (Catalog *catalog, int Ncatalog);
    623628int UpdateMosaic (Catalog *catalog, int Ncatalog);
    624629int UpdateMeasures (Catalog *catalog, int Ncatalog);
  • branches/czw_branch/20170908/Ohana/src/relastro/src

  • branches/czw_branch/20170908/Ohana/src/relastro/src/BrightCatalog.c

    r39995 r40477  
    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);
     
    361364    gfits_define_bintable_column (&theader, "D", "DEC",      "dec",                        "degrees", 1.0, 0.0);
    362365    gfits_define_bintable_column (&theader, "E", "MAG_SYS",  "magnitude (sys)",             NULL,    1.0, 0.0);
    363     gfits_define_bintable_column (&theader, "E", "MAG_CAL",  "magnitude (cal)",             NULL,    1.0, 0.0);
     366    gfits_define_bintable_column (&theader, "E", "MCAL_PSF", "magnitude (cal)",             NULL,    1.0, 0.0);
     367    gfits_define_bintable_column (&theader, "E", "MCAL_APER","magnitude (cal)",             NULL,    1.0, 0.0);
    364368    gfits_define_bintable_column (&theader, "E", "MAG_ERR",  "magnitude (err)",             NULL,    1.0, 0.0);
    365369    gfits_define_bintable_column (&theader, "E", "AIRMASS",  "airmass",                     NULL,    1.0, 0.0);
     
    385389    double *D         ; ALLOCATE (D        ,  double, catalog->Nmeasure);
    386390    float  *M         ; ALLOCATE (M        ,  float,  catalog->Nmeasure);
    387     float  *Mcal      ; ALLOCATE (Mcal     ,  float,  catalog->Nmeasure);
     391    float  *McalPSF   ; ALLOCATE (McalPSF  ,  float,  catalog->Nmeasure);
     392    float  *McalAPER  ; ALLOCATE (McalAPER ,  float,  catalog->Nmeasure);
    388393    float  *dM        ; ALLOCATE (dM       ,  float,  catalog->Nmeasure);
    389394    float  *airmass   ; ALLOCATE (airmass  ,  float,  catalog->Nmeasure);
     
    408413      D[i]        = measure[i].D        ;
    409414      M[i]        = measure[i].M        ;
    410       Mcal[i]     = measure[i].Mcal     ;
     415      McalPSF[i]  = measure[i].McalPSF  ;
     416      McalAPER[i] = measure[i].McalAPER ;
    411417      dM[i]       = measure[i].dM       ;
    412418      airmass[i]  = measure[i].airmass  ;
     
    434440    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
    435441    gfits_set_bintable_column (&theader, &ftable, "MAG_SYS",    M,         catalog->Nmeasure);
    436     gfits_set_bintable_column (&theader, &ftable, "MAG_CAL",    Mcal,      catalog->Nmeasure);
     442    gfits_set_bintable_column (&theader, &ftable, "MCAL_PSF",   McalPSF,   catalog->Nmeasure);
     443    gfits_set_bintable_column (&theader, &ftable, "MCAL_APER",  McalAPER,  catalog->Nmeasure);
    437444    gfits_set_bintable_column (&theader, &ftable, "MAG_ERR",    dM,        catalog->Nmeasure);
    438445    gfits_set_bintable_column (&theader, &ftable, "AIRMASS",    airmass,   catalog->Nmeasure);
     
    454461    free (D       );
    455462    free (M       );
    456     free (Mcal    );
     463    free (McalPSF );
     464    free (McalAPER);
    457465    free (dM      );
    458466    free (airmass );
     
    694702    SecFilt *secfilt = catalog->secfilt;
    695703    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   ;
     704      M     [i]       = secfilt[i].MpsfChp ;
     705      dM    [i]       = secfilt[i].dMpsfChp;
     706      Mchisq[i]       = secfilt[i].Mchisq  ;
     707      flags [i]       = secfilt[i].flags   ;
     708      Ncode [i]       = secfilt[i].Ncode   ;
     709      Nused [i]       = secfilt[i].Nused   ;
     710      Mmin  [i]       = secfilt[i].Mmin    ;
     711      Mmax  [i]       = secfilt[i].Mmax    ;
    704712    }
    705713
  • branches/czw_branch/20170908/Ohana/src/relastro/src/ImageOps.c

    r39926 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relastro/src/MosaicOps.c

    r39457 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relastro/src/UpdateChips.c

    r39926 r40477  
    8888    raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC);
    8989    if (!raw) {
     90      // fprintf (stderr, "skip 1 %s\n", image[i].name);
    9091      Nskip ++;
    9192      mode[i] = 0;
     
    9394    }
    9495    if (Nraw <= IMFIT_TOO_FEW) {
     96      // fprintf (stderr, "skip 2 %s\n", image[i].name);
    9597      Nskip ++;
    9698      mode[i] = 0;
     
    102104    ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC);
    103105    if (!ref) {
     106      // fprintf (stderr, "skip 3 %s\n", image[i].name);
    104107      Nskip ++;
    105108      mode[i] = 0;
     
    116119    // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions.
    117120    assert (Nraw == Nref);
     121
     122    if (IMSTATS_ONLY) {
     123      int Nstat;
     124      float dLsig, dMsig, dRsig;
     125      GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nraw, IMFIT_SYS_SIGMA_LIM);
     126
     127      // XXX: I need to convert dLsig, dMsig from degrees to pixels
     128      dLsig *= 3600.0;
     129      dMsig *= 3600.0;
     130
     131      image[i].dXpixSys = dLsig;
     132      image[i].dYpixSys = dMsig;
     133      image[i].nFitAstrom = Nstat;
     134      continue;
     135    }
    118136
    119137    // save these in case of failure
  • branches/czw_branch/20170908/Ohana/src/relastro/src/UpdateMeasures.c

    r39926 r40477  
    4747      }
    4848
    49       off_t im = getImageByID (measureT->imageID);
     49      Average *average = &catalog[i].average[measureB->averef];
     50      int FOUND_TEST = FALSE;
     51      FOUND_TEST |= (average[0].objID == OBJ_ID_SRC) && (average[0].catID == CAT_ID_SRC);
     52      FOUND_TEST |= (average[0].objID == OBJ_ID_DST) && (average[0].catID == CAT_ID_DST);
     53      if (FOUND_TEST) {
     54        fprintf (stderr, "found test object\n");
     55      }
     56
     57      // we need this below but cannot declare it after the label update_this_measure:
     58      off_t im;
     59
     60      // we have a few options to include/exclude specific types of measurements
     61      if (UPDATE_ALL_MEASURE) goto update_this_measure;
     62      if (isGPC1chip (measureT->photcode)  && UPDATE_PS1_CHIP_MEASURE) goto update_this_measure;
     63      if (isGPC1stack (measureT->photcode) && UPDATE_PS1_STACK_MEASURE) goto update_this_measure;
     64      if (isHSCchip (measureT->photcode)   && UPDATE_HSC_MEASURE) goto update_this_measure;
     65      if (isCFHchip (measureT->photcode)   && UPDATE_CFH_MEASURE) goto update_this_measure;
     66      continue; // skip all others
     67
     68      update_this_measure:
     69      im = getImageByID (measureT->imageID);
    5070      if (im < 0) continue; // detections without imageIDs are not associated with a known image (eg, refs)
    5171
     
    114134      }
    115135
    116       // only modify the chip coordinates
    117       if (UPDATE_PS1_STACK_MEASURE && isGPC1stack (measureT->photcode)) {
    118         measureT->R = R;
    119         measureT->D = D;
    120         if (measureB) {
    121           measureB->R = R;
    122           measureB->D = D;
    123         }
    124       }
    125       // only modify the chip coordinates
    126       if (UPDATE_PS1_CHIP_MEASURE && isGPC1chip (measureT->photcode)) {
    127         measureT->R = R;
    128         measureT->D = D;
    129         if (measureB) {
    130           measureB->R = R;
    131           measureB->D = D;
    132         }
    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         }
     136      // modify the measure coordinates
     137      measureT->R = R;
     138      measureT->D = D;
     139      if (measureB) {
     140        measureB->R = R;
     141        measureB->D = D;
    151142      }
    152143    }
  • branches/czw_branch/20170908/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r39926 r40477  
    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");
  • branches/czw_branch/20170908/Ohana/src/relastro/src/UpdateObjects.c

    r39926 r40477  
    127127  int k;
    128128
     129  // we need to chose to do something here...
     130  int valid = UPDATE_ALL_MEASURE;
     131  valid |= UPDATE_PS1_CHIP_MEASURE;
     132  valid |= UPDATE_HSC_MEASURE;
     133  valid |= UPDATE_CFH_MEASURE;
     134  if (!valid) return FALSE;
     135
    129136  /* calculate the average value of R,D for a single star */
    130 
    131137  FitAstromResult fitPos, fitPM, fitPar;
    132138  FitAstromResultInit (&fitPos);
     
    583589  int status;
    584590
     591  // we need to chose to do something here...
     592  if (!UPDATE_PS1_STACK_MEASURE) return FALSE;
     593
    585594  // set the default values
    586595  average[0].Rstk  = NAN; // RA in degrees
     
    794803    Npoints++;
    795804
     805    // NOTE: if 'isStack' is true, we will never see these photcode values
    796806    hasGAIA  =  (measure[k].photcode == 1030);
    797807    has2MASS = ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013));
     
    808818  }
    809819 
    810   // XXX flag measurements from stars with 2MASS
    811   for (k = 0; k < average[0].Nmeasure; k++) {
    812     // reset the bit to note that a detection was used (or not)
     820  // flag measurements from stars with 2MASS, GAIA, TYCHO
     821  // NOTE: if 'isStack' is TRUE, these will not be correctly set.
     822  // ONLY do this loop if not(isStack)
     823  for (k = 0; !isStack && (k < average[0].Nmeasure); k++) {
     824    // reset the bit to note that an object does or does not have the value
    813825    if (has2MASS) {
    814826      measure[k].dbFlags |=  ID_MEAS_OBJECT_HAS_2MASS;
  • branches/czw_branch/20170908/Ohana/src/relastro/src/UpdateStacks.c

    r39926 r40477  
    1111  off_t Nskip = 0;
    1212  off_t Nmeas = 0;
     13  off_t NnewFit = 0;
     14  off_t NoldFit = 0;
    1315
    1416  // measure the scatter for each stack
     
    4345    assert (Nraw == Nref);
    4446
    45     int Nstat;
    46     float dLsig, dMsig, dRsig;
    47     GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nraw, IMFIT_SYS_SIGMA_LIM);
     47    // the natural default for stacks is to NOT re-fit
     48    if (FIT_STACKS == FALSE) {
     49      int Nstat;
     50      float dLsig, dMsig, dRsig;
     51      GetScatterRawRef(&dLsig, &dMsig, &dRsig, &Nstat, raw, ref, Nraw, IMFIT_SYS_SIGMA_LIM);
    4852
    49     // XXX: I need to convert dLsig, dMsig from degrees to pixels
    50     dLsig *= 3600.0;
    51     dMsig *= 3600.0;
     53      // XXX: I need to convert dLsig, dMsig from degrees to pixels
     54      dLsig *= 3600.0;
     55      dMsig *= 3600.0;
    5256
    53     image[i].dXpixSys = dLsig;
    54     image[i].dYpixSys = dMsig;
    55     image[i].nFitAstrom = Nstat;
     57      image[i].dXpixSys = dLsig;
     58      image[i].dYpixSys = dMsig;
     59      image[i].nFitAstrom = Nstat;
     60      continue;
     61    }
     62
     63    // save these in case of failure
     64    Coords oldCoords;
     65    SaveCoords (&oldCoords, &image[i].coords);
     66
     67    float dXpixSys = image[i].dXpixSys;
     68    float dYpixSys = image[i].dYpixSys;
     69    int   nFitAstr = image[i].nFitAstrom;
     70
     71    // FitChip does iterative, clipped fitting
     72    if (!FitChip (raw, ref, Nraw, &image[i])) {
     73      if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT", Nused %d of %d\n", image[i].name, i, Nraw, image[i].nFitAstrom, image[i].nstar);
     74
     75      // restore status quo ante (replace truMap with tmpMap)
     76      RestoreCoords (&image[i].coords, &oldCoords, &image[i]);
     77      image[i].dXpixSys = dXpixSys;
     78      image[i].dYpixSys = dYpixSys;
     79      image[i].nFitAstrom = nFitAstr;
     80
     81      NoldFit ++;
     82      free (raw);
     83      free (ref);
     84      continue;
     85    }
     86
     87    AstromOffsetMapFree (oldCoords.offsetMap);
     88
     89    // Apply the modified coords back to the measure.R,D.  Note that raw.R,D, ref.L,M, etc
     90    // are all automatically updated in this block because they are re-generated from
     91    // image.coords on each pass.
     92    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
     93
     94    NnewFit ++;
     95    free (raw);
     96    free (ref);
    5697  }
    5798
  • branches/czw_branch/20170908/Ohana/src/relastro/src/args.c

    r39926 r40477  
    6868  }
    6969
     70  // the default is to only measure the scatter for the stacks, not to perform a new fit
     71  FIT_STACKS = FALSE;
     72  if ((N = get_argument (argc, argv, "-fit-stacks"))) {
     73    remove_argument (N, &argc, argv);
     74    FIT_STACKS = TRUE;
     75  }
     76
    7077  REPAIR_STACKS = FALSE;
    7178  if ((N = get_argument (argc, argv, "-repair-stacks-on-update"))) {
     
    8693  }
    8794
     95  // only update the fit statistics (systematic floor)
     96  IMSTATS_ONLY = FALSE;
     97  if ((N = get_argument (argc, argv, "-imstats-only"))) {
     98    remove_argument (N, &argc, argv);
     99    IMSTATS_ONLY = TRUE;
     100  }
     101
    88102  // elements needed for parallel regions / parallel images
    89103  MANUAL_UNIQUER = NULL;
     
    158172  }
    159173
     174  UPDATE_ALL_MEASURE = FALSE;
     175  if ((N = get_argument (argc, argv, "-update-all-cameras"))) {
     176    remove_argument (N, &argc, argv);
     177    UPDATE_ALL_MEASURE = TRUE;
     178  }
    160179  UPDATE_PS1_STACK_MEASURE = FALSE;
    161180  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     
    179198  }
    180199  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");
     200    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     201      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");
    183202      exit (2);
    184203    }
    185204  }
    186   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) {
     205  if (RELASTRO_OP == OP_UPDATE_OBJECTS) {
     206    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     207      fprintf (stderr, "for -update-objects, need to select at least one of -update-all-cameras, -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
     208      exit (2);
     209    }
     210  }
     211  if ((RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES) || (RELASTRO_OP == OP_IMAGES)) {
     212    if (APPLY_OFFSETS && !UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
    188213      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");
    189214      exit (2);
     
    300325    remove_argument (N, &argc, argv);
    301326    FIT_TARGET = SET_CHIPS;
     327  }
     328  if ((N = get_argument (argc, argv, "-set-stacks"))) {
     329    remove_argument (N, &argc, argv);
     330    FIT_TARGET = SET_STACKS;
    302331  }
    303332
     
    858887  }
    859888
     889  // the default is to only measure the scatter for the stacks, not to perform a new fit
     890  FIT_STACKS = FALSE;
     891  if ((N = get_argument (argc, argv, "-fit-stacks"))) {
     892    remove_argument (N, &argc, argv);
     893    FIT_STACKS = TRUE;
     894  }
     895
    860896  REPAIR_STACKS = FALSE;
    861897  if ((N = get_argument (argc, argv, "-repair-stacks-on-update"))) {
     
    869905  }
    870906
     907  // only update the fit statistics (systematic floor)
     908  IMSTATS_ONLY = FALSE;
     909  if ((N = get_argument (argc, argv, "-imstats-only"))) {
     910    remove_argument (N, &argc, argv);
     911    IMSTATS_ONLY = TRUE;
     912  }
     913
    871914  SKIP_PS1_CHIP = FALSE;
    872915  if ((N = get_argument (argc, argv, "-skip-ps1-chip"))) {
     
    890933  }
    891934
     935  UPDATE_ALL_MEASURE = FALSE;
     936  if ((N = get_argument (argc, argv, "-update-all-cameras"))) {
     937    remove_argument (N, &argc, argv);
     938    UPDATE_ALL_MEASURE = TRUE;
     939  }
    892940  UPDATE_PS1_STACK_MEASURE = FALSE;
    893941  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     
    911959  }
    912960  if (RELASTRO_OP == OP_UPDATE_OFFSETS) {
    913     if (!UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     961    if (!UPDATE_ALL_MEASURE && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
    914962      fprintf (stderr, "for -update-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
    915963      exit (2);
  • branches/czw_branch/20170908/Ohana/src/relastro/src/launch_region_hosts.c

    r39926 r40477  
    117117        strextend (&command, "-set-chips");
    118118        break;
     119      case SET_STACKS:
     120        strextend (&command, "-set-stacks");
     121        break;
    119122      case TARGET_NONE:
    120123        abort();
     
    151154    if (SKIP_CFH)            strextend (&command, "-skip-cfh");
    152155
     156    if (FIT_STACKS)          strextend (&command, "-fit-stacks");
     157    if (IMSTATS_ONLY)        strextend (&command, "-imstats-only");
     158
    153159    strextend (&command, "-nloop %d", NLOOP);
    154160    strextend (&command, "-threads %d", NTHREADS);
  • branches/czw_branch/20170908/Ohana/src/relastro/src/relastro_images.c

    r39926 r40477  
    9999      UpdateChips (catalog, Ncatalog, 0);   // measure.X,Y -> R,D, fit image.coords
    100100      MARKTIME("update chips: %f sec\n", dtime);
     101      break;
    101102
     103    case SET_STACKS:
     104      // we just want to fit the selected stacks to the mean positions
     105      UpdateStacks (catalog, Ncatalog);
     106      MARKTIME("update stacks : %f sec\n", dtime);
    102107      break;
    103108
  • branches/czw_branch/20170908/Ohana/src/relastro/src/relastro_parallel_images.c

    r39926 r40477  
    150150      }
    151151
    152       // measure scatter for stacks
     152      // measure astrometry or scatter [default] for stacks
    153153      UpdateStacks (catalog, Ncatalog);
    154154      LOGRTIME("UpdateStacks on %s, host %d: %f sec\n", myHostName, REGION_HOST_ID, dtime);
     
    156156      // create summary plots of the process
    157157      // relastroVisualSummaryChips();
     158      break;
     159
     160    case SET_STACKS:
     161      // we just want to fit the selected stacks to the mean positions
     162      share_mean_pos (catalog, Ncatalog, regionHosts, 0);
     163      slurp_mean_pos (catalog, Ncatalog, regionHosts, 0);
     164      UpdateStacks (catalog, Ncatalog);
     165      share_image_pos (regionHosts, 0);
     166      slurp_image_pos (catalog, Ncatalog, regionHosts, 0);
     167      MARKTIME("update stacks : %f sec\n", dtime);
    158168      break;
    159169
  • branches/czw_branch/20170908/Ohana/src/relastro/src/select_images.c

    r39926 r40477  
    114114    }
    115115    if (FALSE && !strncmp(timage[i].name, "o6227g0311o", 10)) {
     116      fprintf (stderr, "test image 2\n");
     117    }
     118
     119    // RINGS.V3.skycell.2634.034.stk.3411510.skycal.3811673.cmf[SkyChip.hdr]
     120    if (!strncmp(timage[i].name, "RINGS.V3.skycell.2634.034.stk.3411510", strlen("RINGS.V3.skycell.2634.034.stk.3411510"))) {
    116121      fprintf (stderr, "test image 2\n");
    117122    }
  • branches/czw_branch/20170908/Ohana/src/relphot/include/relphot.h

    r39926 r40477  
    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;
     
    291294int    PARALLEL_SERIAL;
    292295char  *MANUAL_UNIQUER;
     296
     297int    SKIP_PARALLEL_GROUPS;
    293298
    294299int    PARALLEL_REGIONS_MANUAL;
     
    336341int    SyntheticPhotometry;
    337342
     343int    USE_MCAL_PSF_FOR_STACK_APER;
     344
    338345char  *PhotcodeList;
    339346
     
    404411int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
    405412
     413void clearImages (void);
     414void checkImages (char *name);
     415int dumpMags (FILE *fout, Catalog *catalog, int Ncatalog);
     416
    406417void makeMosaics (Image *image, off_t Nimage, int mergeMcal);
    407418Mosaic *getMosaicForImage (off_t im);
     
    422433off_t         getImageEntry       PROTO((off_t meas, int cat));
    423434
    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));
     435float         getMcal             PROTO((off_t meas, int cat, dvoMagClassType class));
    426436float         getMflat            PROTO((off_t meas, int cat, FlatCorrectionTable *flatcorr, Catalog *catalog));
    427437float         getMgrid            PROTO((off_t meas, int cat));
    428438float         getMmos             PROTO((off_t meas, int cat));
    429 float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat));
     439float         getMrel             PROTO((Catalog *catalog, off_t meas, int cat, dvoMagClassType class, dvoMagSourceType source));
    430440short         getUbercalDist      PROTO((off_t meas, int cat));
    431441float         getCenterOffset     PROTO((off_t meas, int cat, Measure *measure, unsigned int *myID));
  • branches/czw_branch/20170908/Ohana/src/relphot/src/BrightCatalog.c

    r39478 r40477  
    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 );
  • branches/czw_branch/20170908/Ohana/src/relphot/src/GridOps.c

    r39632 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relphot/src/ImageMagIO.c

    r37037 r40477  
    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      );
  • branches/czw_branch/20170908/Ohana/src/relphot/src/ImageOps.c

    r39643 r40477  
    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}
  • branches/czw_branch/20170908/Ohana/src/relphot/src/ImageSubset.c

    r39478 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/relphot/src/MosaicOps.c

    r39632 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/relphot/src/StarOps.c

    r40019 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/relphot/src/args.c

    r39926 r40477  
    136136    remove_argument (N, &argc, argv);
    137137  }
     138  SKIP_PARALLEL_GROUPS = 0;
     139  if ((N = get_argument (argc, argv, "-skip-parallel-groups"))) {
     140    remove_argument (N, &argc, argv);
     141    SKIP_PARALLEL_GROUPS = atoi(argv[N]);
     142    remove_argument (N, &argc, argv);
     143  }
    138144
    139145  // elements needed for parallel regions / parallel images
     
    325331    remove_argument (N, &argc, argv);
    326332    CALIBRATE_STACKS_AND_WARPS = TRUE;
     333  }
     334  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     335  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     336    remove_argument (N, &argc, argv);
     337    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
    327338  }
    328339
     
    544555  PARALLEL_MANUAL = FALSE;
    545556  PARALLEL_SERIAL = FALSE;
     557  SKIP_PARALLEL_GROUPS = 0;
    546558
    547559  HOST_ID = 0;
     
    694706    remove_argument (N, &argc, argv);
    695707    KEEP_UBERCAL = FALSE;
     708  }
     709
     710  USE_MCAL_PSF_FOR_STACK_APER = FALSE;
     711  if ((N = get_argument (argc, argv, "-use-mcal-psf-for-stack-aper"))) {
     712    remove_argument (N, &argc, argv);
     713    USE_MCAL_PSF_FOR_STACK_APER = TRUE;
    696714  }
    697715
  • branches/czw_branch/20170908/Ohana/src/relphot/src/bcatalog.c

    r39641 r40477  
    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        }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/launch_region_hosts.c

    r39511 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relphot/src/liststats.c

    r39648 r40477  
    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}
  • branches/czw_branch/20170908/Ohana/src/relphot/src/load_images.c

    r39642 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/plot_scatter.c

    r37037 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relphot/src/plotstuff.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/relphot/src/reload_catalogs.c

    r39926 r40477  
    180180  for (i = 0; i < Ngroups; i++) {
    181181    // update only a group of unique machines at a time
     182    if (i < SKIP_PARALLEL_GROUPS) continue;
    182183    reload_catalog_parallel_group (&groups[i], sky, imageFile);
    183184  }
     
    247248    if (SYNTH_ZERO_POINTS) { strextend (&command, "-synthphot-zpts %s", SYNTH_ZERO_POINTS); }
    248249    if (USE_BASIC_CHECK)   {  strextend (&command, "-basic-image-search"); }
     250    if (USE_MCAL_PSF_FOR_STACK_APER) { strextend (&command, "-use-mcal-psf-for-stack-aper"); }
    249251
    250252    if (!(STAGES & STAGE_CHIP))  { strextend (&command, "-skip-chip"); }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_images.c

    r39643 r40477  
    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)) {
  • branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_objects.c

    r39926 r40477  
    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"); }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_parallel_images.c

    r39643 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_parallel_regions.c

    r39643 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/relphot/src/relphot_synthphot_catalog.c

    r38062 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/select_images.c

    r39648 r40477  
    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 ++;
  • branches/czw_branch/20170908/Ohana/src/relphot/src/setMrelCatalog.c

    r39926 r40477  
    22
    33# if (0)
    4 # define TEST_OBJ_ID 0x0000000e
    5 # define TEST_CAT_ID 0x000076ee
     4# define TEST_OBJ_ID 0x000149b0
     5# define TEST_CAT_ID 0x00000001
    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      // XXX EAM : this was int SNvalue -- isfinite(SNvalue) would always be finite
     636      float SNvalue = isfinite(measure[k].dM) ? 1.0 / hypot (measure[k].dM, MIN_ERROR) : NAN;
     637      int psfQFperfAboveLimit = isfinite(SNvalue) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95);
     638
     639      // ** determine the BEST level
     640      int bestLevel = 0;
     641      if (!isPrimary && !psfQFperfAboveLimit) bestLevel = 1;
     642      if ( isPrimary && !psfQFperfAboveLimit) bestLevel = 2;
     643      if (!isPrimary &&  psfQFperfAboveLimit) bestLevel = 3;
     644      if ( isPrimary &&  psfQFperfAboveLimit) bestLevel = 4;
     645
     646      // here is the rule for choosing the best value:
     647      float bestValue = (bestLevel > 2) ? SNvalue : measure[k].psfQFperf;
     648
     649      // if we have not reached this level before, set the new level
     650      if (bestLevelMax < bestLevel) {
     651        bestValueMax = bestValue;
     652        bestLevelMax = bestLevel;
     653        bestEntryMax = k;
     654      }
     655      // if we have reached this level before, set the new value if we beat the old one
     656      if ((bestLevelMax == bestLevel) && (bestValueMax < bestValue)) {
     657        bestValueMax = bestValue;
     658        bestEntryMax = k;
     659      }
     660      myAssert (bestEntryMax > -1, "this should not happen");
     661
     662      // ** determine the PRIMARY level
     663      int primaryLevel = 0;
     664      if ( isPrimary && !psfQFperfAboveLimit) primaryLevel = 1;
     665      if ( isPrimary &&  psfQFperfAboveLimit) primaryLevel = 2;
     666
     667      // here is the rule for choosing the PRIMARY value:
     668      float primaryValue = 0.0;
     669      if (primaryLevel == 1) { primaryValue = measure[k].psfQFperf; }
     670      if (primaryLevel == 2) { primaryValue = SNvalue; }
     671
     672      // if we have not reached this level before, set the new level
     673      if (isPrimary && (primaryLevelMax < primaryLevel)) {
     674        primaryValueMax = primaryValue;
     675        primaryLevelMax = primaryLevel;
     676        primaryEntryMax = k;
     677      }
     678      // if we have reached this level before, set the new value if we beat the old one
     679      if (isPrimary && (primaryLevelMax == primaryLevel) && (primaryValueMax < primaryValue)) {
     680        primaryValueMax = primaryValue;
     681        primaryEntryMax = k;
     682      }
     683    }
     684
     685    // if we do not have a stack measurement for this photcode, skip everything below
     686    if (!haveStack) continue;
     687 
     688    // now we have a BEST and a PRIMARY entry (may be the same entry)
     689
     690    off_t meas = bestEntryMax;
     691    off_t measSeq = meas + measureOffset;
     692
     693    myAssert (meas >= 0, "this should not happen");
     694
     695    // measurements without an image are either external reference photometry or
     696    // data for which the associated image has not been loaded (probably because of
     697    // overlaps).  we only want measurements associated with stack images in this loop
     698   
     699    // match measurement to its image (this is just a check, right?)
     700    if (getImageEntry (measSeq, cat) < 0) {
    622701      // measurements without an image are either external reference photometry or
    623702      // 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);
     703      // overlaps).  Msys + measure.Mcal is our best guess of the true magnitude
     704      McalPSF  = measure[meas].McalPSF; // check that this is zero for loaded REF value
     705      McalAPER = McalPSF; // check that this is zero for loaded REF value
     706      Mmos     = 0.0;
     707      Mgrid    = 0.0;
     708    } else {
     709      McalPSF   = getMcal  (measSeq, cat, MAG_CLASS_PSF);
     710      McalAPER  = USE_MCAL_PSF_FOR_STACK_APER ? getMcal  (measSeq, cat, MAG_CLASS_PSF) : getMcal  (measSeq, cat, MAG_CLASS_KRON);
     711      Mmos      = getMmos  (measSeq, cat);
     712      Mgrid     = getMgrid (measSeq, cat);
     713    }
     714   
     715    // ** Here is the math to relate mag,zp to flux
    675716
    676717    // flux_cgs : erg sec^1 cm^-2 Hz^-1
     
    703744    // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56)
    704745
     746    // get the zero point for the selected image
     747    // Use a different zero point for the PSF-like and APERTURE-like magnitudes
     748    float zpPSF  = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalPSF  + Mmos + Mgrid);
     749    float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid);
     750
    705751    // zpFactor to go from instrumental flux to Janskies
    706     float zpFactor = pow(10.0, -0.4*zp + 3.56);
     752    float zpFactorPSF  = pow(10.0, -0.4*zpPSF  + 3.56);
     753    float zpFactorAPER = pow(10.0, -0.4*zpAPER + 3.56);
    707754
    708755    // 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;
     756    secfilt[Nsec].FpsfStk   = zpFactorPSF  * measure[meas].FluxPSF; 
     757    secfilt[Nsec].dFpsfStk  = zpFactorPSF  * measure[meas].dFluxPSF;
     758    secfilt[Nsec].FkronStk  = zpFactorAPER * measure[meas].FluxKron;
     759    secfilt[Nsec].dFkronStk = zpFactorAPER * measure[meas].dFluxKron;
     760    secfilt[Nsec].FapStk    = zpFactorAPER * measure[meas].FluxAp;
    714761
    715762    // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245).  we are going to
    716763    // use PSF flux error instead here:
    717     // secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxAp;
    718     secfilt[Nsec].dFapStk   = zpFactor * measure[k].dFluxPSF;
     764    // secfilt[Nsec].dFapStk   = zpFactorAPER * measure[meas].dFluxAp;
     765    secfilt[Nsec].dFapStk   = zpFactorAPER * measure[meas].dFluxPSF;
    719766
    720767    // 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;
     768    secfilt[Nsec].MpsfStk   = (measure[meas].FluxPSF  > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk)  : NAN;
     769    secfilt[Nsec].MkronStk  = (measure[meas].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN;
     770    secfilt[Nsec].MapStk    = (measure[meas].FluxAp   > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk)   : NAN;
     771
     772    // record the measurement which gave the best value
     773    secfilt[Nsec].stackBestOff = (bestEntryMax == -1) ? -1 : bestEntryMax + measureOffset;
    726774    myAssert (secfilt[Nsec].stackBestOff <= catalog[0].Nmeasure, "stackBestOff out of range");
    727775
    728     secfilt[Nsec].Nstack    = Nstack;
     776    // record the selected primary measurement
     777    secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset;
     778    myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range");
     779
     780    // this is the selected measurement used by secfilt[]
     781    measure[meas].dbFlags |= ID_MEAS_STACK_PHOT_SRC;
     782    if (Nprimary) {
     783      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY;
     784      if (Nprimary > 1) {
     785        secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY_MULTIPLE;
     786      }
     787    }
     788
     789    // stack measurement used for 'best' was a detection (not forced from the other bands)
     790    if ((measure[bestEntryMax].photFlags2 & 0x00000004) == 0) {
     791      secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET;
     792    }
     793
     794    // stack measurement used for 'primary' was a detection (not forced from the other bands)
     795    if ((primaryEntryMax >= 0) && ((measure[primaryEntryMax].photFlags2 & 0x00000004) == 0)) {
     796      secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET;
     797    }
     798
     799    secfilt[Nsec].flags |= ID_SECF_HAS_PS1_STACK;
     800
     801    // NOTE: negative and insignificant flux values are allowed, but not NAN flux values
     802    // float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF);
     803   
     804    // data quality assessment
     805    isBad |= (measure[meas].photFlags & photcodes[Ns][0].photomBadMask);
     806    isBad |= (measure[meas].psfQF < 0.85);
     807    isBad |= isnan(measure[meas].psfQF);
     808    isBad |= measure[meas].dM > 0.2; // S/N < 5.0
     809
     810    isSuspect |= (measure[meas].photFlags & photcodes[Ns][0].photomPoorMask);
     811    isSuspect |= (measure[meas].psfQFperf < 0.85);
     812
     813    if (!isSuspect && !isBad) {
     814      NstackGood ++;
     815    }
     816    if (isSuspect && !isBad) {
     817      NstackSuspect ++;
     818    }
     819
     820    secfilt[Nsec].Nstack    = NstackMeas;
    729821    secfilt[Nsec].NstackDet = NstackDet;
    730822
    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;
    747823  } // Nsecfilt loop
    748824
     
    755831
    756832  int PrimaryIsBest = TRUE;
    757   for (Ns = 0; Ns < Nphotcodes; Ns++) {
     833  for (int Ns = 0; Ns < Nphotcodes; Ns++) {
    758834    if (!(secfilt[Ns].flags & ID_SECF_HAS_PS1_STACK)) continue; // no stack detection in PS1, nothing is best
    759835    if (secfilt[Ns].flags & ID_SECF_STACK_PRIMARY) continue;    // primary stack detection is best
     
    780856// * no grid, no mosaic, no 2MASS, no SYNTH, no Ubercal, no flatcorr
    781857// analysis is done on flux, not mags (as the faintest objects will be nearly insignificant)
     858
     859// Although I calculate McalAPER for exposures, I am only using McalPSF for warps..
     860// Note in StarOps.c:setMcalOutput I am setting measure->McalAPER to image->McalPSF for
     861// chips and warps, but not stacks
     862
    782863int setMrelAverageForcedWarp (Catalog *catalog, int cat, off_t ave, int Nsecfilt, FlatCorrectionTable *flatcorr, SetMrelInfo *results) {
    783864  OHANA_UNUSED_PARAM(flatcorr);
     
    857938      // data for which the associated image has not been loaded (probably because of
    858939      // 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
     940      Mcal = measure[k].McalPSF; // check that this is zero for loaded REF value
    860941    } 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);
     942      Mcal  = getMcal (meas, cat, MAG_CLASS_PSF);
    864943      if (isnan(Mcal))  SKIP_THIS_MEAS(Ncal);
    865944    }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/setMrelFinal.c

    r39632 r40477  
    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        }
  • branches/czw_branch/20170908/Ohana/src/relphot/src/share_image_mags.c

    r36630 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/relphot/src/share_mean_mags.c

    r39457 r40477  
    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
  • branches/czw_branch/20170908/Ohana/src/relphot/src/synthetic_mags.c

    r39457 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/tools/src/fields.c

    r38441 r40477  
    9696          }
    9797        }
     98        // we are checking each extension to see if it matches the regex.
    9899        if (!regexec (&preg, extname, 0, NULL, 0)) {
    99100          GotField &= print_fields (filename, extname, &header, argc, argv);
     
    105106        Nextend ++;
    106107
     108        // this implementation is very inefficient!
     109        // since we are checking each header for a regex, we should
     110        // loop over all extensions once.  the function below reads the
     111        // entire file a second time
    107112        GotFile &= gfits_read_Xheader (filename, &header, Nextend);
    108113        continue;
  • branches/czw_branch/20170908/Ohana/src/uniphot/include/setphot.h

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

    r37043 r40477  
    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  }
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/dumpresult.c

    r31160 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/fit_groups.c

    r31160 r40477  
    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);
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/match_zpts_to_images.c

    r37807 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/update_catalog_setastrom.c

    r39288 r40477  
    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;
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/update_catalog_setphot.c

    r39926 r40477  
    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) {
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/update_catalog_uniphot.c

    r33654 r40477  
    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    }
  • branches/czw_branch/20170908/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r38986 r40477  
    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.