IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31261


Ignore:
Timestamp:
Apr 10, 2011, 4:42:40 PM (15 years ago)
Author:
eugene
Message:

modifications to relphot to support multi-filter analysis (not yet working)

Location:
branches/eam_branches/ipp-20110404/Ohana/src/relphot
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/include/relphot.h

    r31260 r31261  
    8585int    RELPHOT_GRID_BINNING;
    8686
    87 PhotCode      *photcode;
    88 int            PhotNsec;
    89 int            PhotSec;
     87int      *photseclist;
     88int      Nphotcodes;
     89PhotCode **photcodes;
     90// int            PhotSec;
     91// int            PhotNsec;
    9092
    9193PhotCode      *refPhotcode;
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/GridOps.c

    r28241 r31261  
    410410        // select the color- and airmass-corrected observed magnitude for this star
    411411        // XXX need to be able to turn off the color-correction until initial average mags are found
    412         // Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
    413412        Msys = PhotCat (&catalog[c].measure[m]);
    414413        if (isnan(Msys)) {
     
    528527  if (!USE_GRID) return;
    529528
     529  int Nsecfilt = GetPhotcodeNsecfilt ();
     530
    530531  Nmax = Nlist[0];
    531532  for (i = 0; i < Ngrid; i++) {
     
    566567     
    567568      n = catalog[c].measure[m].averef;
    568       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     569      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
    569570      if (isnan(Msys)) {
    570571        Nsys++;
     
    612613
    613614  if (!USE_GRID) return;
     615
     616  int Nsecfilt = GetPhotcodeNsecfilt ();
    614617
    615618  N = 0;
     
    642645
    643646      n = catalog[c].measure[m].averef;
    644       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     647      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
    645648
    646649      xlist[N] = Xmeas[c][m];
     
    704707  gfits_create_matrix (&header, &matrix);
    705708  gfits_modify (&header, "NEXTEND", OFF_T_FMT, 1,  Nimage + 3);
    706   gfits_modify (&header, "FILTER", "%s", 1, photcode[0].name);
     709  gfits_modify (&header, "FILTER", "%s", 1, photcodes[0][0].name);  // XXXX note that this expects a single photcode, enforced in initialize.d
    707710  gfits_modify_alt (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis");
    708711
     
    727730  theader.bitpix   = -32;
    728731  gfits_create_Theader (&theader, "IMAGE");
    729   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     732  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    730733  gfits_modify (&theader, "EXTNAME", "%s", 1, "MAG_OFFSET");
    731734  gfits_create_matrix  (&theader, &matrix);
     
    742745  /* save grid Nmeas values */
    743746  gfits_modify (&theader, "EXTNAME", "%s", 1, "NMEAS");
    744   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     747  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    745748  gfits_create_matrix  (&theader, &matrix);
    746749  for (i = 0; i < gridX; i++) {
     
    756759  /* save grid sigma values */
    757760  gfits_modify (&theader, "EXTNAME", "%s", 1, "SIGMA");
    758   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     761  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    759762  gfits_create_matrix  (&theader, &matrix);
    760763  for (i = 0; i < gridX; i++) {
     
    776779
    777780    gfits_modify (&theader, "EXTNAME", "%s", 1, camera.ccdname[N]);
    778     gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     781    gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    779782    gfits_modify (&theader, "NX", "%d", 1, camera.Nx);
    780783    gfits_modify (&theader, "NY", "%d", 1, camera.Ny);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/ImageOps.c

    r30616 r31261  
    128128}
    129129
    130 /* select all image equivalent to the current photcode */
     130/* select all image equivalent to the active photcode set */
    131131void findImages (Catalog *catalog, int Ncatalog) {
    132132
    133133  off_t j;
    134   int i, ecode;
    135 
    136   for (i = 0; i < Ncatalog; i++) {
     134  int i, ecode, Ns, found;
     135 
     136 for (i = 0; i < Ncatalog; i++) {
    137137    for (j = 0; j < catalog[i].Nmeasure; j++) {
    138138      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
    139       if (photcode[0].code != ecode) continue;
     139      found = FALSE;
     140      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     141        if (ecode == photcodes[Ns][0].code) found = TRUE;
     142      }
     143      if (!found) continue;
    140144      matchImage (catalog, j, i);
    141145    }
     
    145149int findCCD (off_t idx, off_t meas, int cat, Measure *measure) {
    146150
    147   int ccdnum;
     151  int ccdnum, found, Ns, ecode;
    148152  double X, Y;
    149153  char *pname, *filter, *p, base[256];
     
    151155  /* identify the ccd on the basis of the photcode name */
    152156  pname = GetPhotcodeNamebyCode (image[idx].photcode);
    153   filter = photcode[0].name;
     157
     158  // XXX this seems quite terrible...
     159  ecode = GetPhotcodeEquivCodebyCode (measure[0].photcode);
     160  found = FALSE;
     161  for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     162    if (ecode == photcodes[Ns][0].code) found = TRUE;
     163  }
     164  if (!found) return (FALSE);
     165
     166  filter = photcodes[Ns][0].name;
    154167  sprintf (base, "%s.%s.", MOSAICNAME, filter);
    155168  if (strncmp (pname, base, strlen (base))) return (FALSE);
     
    307320
    308321  if (FREEZE_IMAGES) return;
     322
     323  int Nsecfilt = GetPhotcodeNsecfilt ();
    309324
    310325  if (PoorImages) {
     
    360375     
    361376      n = catalog[c].measure[m].averef;
    362       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     377      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
    363378      if (isnan(Msys)) {
    364379        Nsys++;
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/MosaicOps.c

    r31260 r31261  
    262262int findMosaics (Catalog *catalog, int Ncatalog) {
    263263 
    264   int i, ecode;
     264  int i, ecode, found, Ns;
    265265  off_t j;
    266266
     
    274274      }
    275275      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
    276       if (photcode[0].code != ecode) continue;
     276      found = FALSE;
     277      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     278        if (ecode == photcodes[Ns][0].code) found = TRUE;
     279      }
     280      if (!found) continue;
    277281      matchMosaics (catalog, j, i);
    278282    }
     
    387391
    388392  off_t i, j, m, c, N, Nmax;
    389   int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys;
     393  int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys, Nsecfilt;
    390394  float Msys, Mrel, Mcal, Mgrid;
    391395  double *list, *dlist, *Mlist, *dMlist;
     
    397401
    398402  image = getimages (&N);
     403
     404  Nsecfilt = GetPhotcodeNsecfilt ();
    399405
    400406  if (PoorImages) {
     
    448454     
    449455      n = catalog[c].measure[m].averef;
    450       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     456      Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*Nsecfilt]);
    451457      if (isnan(Msys)) {
    452458        Nsys++;
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/StarOps.c

    r31258 r31261  
    2929float getMrel (Catalog *catalog, off_t meas, int cat) {
    3030
     31  int Nsec, Nsecfilt, code;
    3132  int ave;
    3233  float value;
    3334
    3435  ave = catalog[cat].measure[meas].averef;
     36  code = catalog[cat].measure[meas].photcode;
     37
     38  // XXX DEP : this should use a flag associated with secfilt
    3539  if (catalog[cat].average[ave].flags & STAR_BAD) return (NAN); 
    3640 
    37   value = catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;
     41  Nsec = GetPhotcodeNsec(code);
     42  Nsecfilt = GetPhotcodeNsecfilt ();
     43
     44  value = catalog[cat].secfilt[Nsecfilt*ave+Nsec].M;
    3845  return (value);
    3946}
     
    4552  float Msys, Mcal, Mmos, Mgrid;
    4653  StatType stats;
    47 
     54  int Nsec, Nsecfilt, ecode;
     55
     56  Nsecfilt = GetPhotcodeNsecfilt ();
    4857  Nfew = Nsys = Nbad = Ncal = Nmos = Ngrid = 0;
    4958
     
    5160    for (j = 0; j < catalog[i].Naverage; j++) {
    5261
    53       /* calculate the average value for a single star */
    54       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    55       m = catalog[i].average[j].measureOffset;
    56 
    57       N = 0;
    58       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    59         if (catalog[i].measure[m].dbFlags & MEAS_BAD) {
    60           Nbad ++;
    61           continue;
    62         }
    63         // XXX allow REF stars (no Image Entry) to be included in the calculation this
    64         // should be optionally set, and should allow for REF stars to be downweighted by
    65         // more than their reported errors.  how such info is carried is unclear...
    66         if (getImageEntry (m, i) < 0) {
    67           Mcal = Mmos = Mgrid = 0;
    68         } else {
    69           Mcal  = getMcal  (m, i);
    70           if (isnan(Mcal)) {
    71             Ncal ++;
     62      int Ns;
     63      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     64
     65        int thisCode = photcodes[Ns][0].code;
     66        Nsec = GetPhotcodeNsec(thisCode);
     67
     68        /* calculate the average value for a single star */
     69        // XXX this flag should be set by secfilt, not average
     70        if (catalog[i].average[j].flags & STAR_BAD) continue; 
     71        m = catalog[i].average[j].measureOffset;
     72
     73        N = 0;
     74        for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     75          // skip measurements that do not match the current photcode
     76          ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
     77          if (ecode != thisCode) { continue; }
     78
     79          if (catalog[i].measure[m].dbFlags & MEAS_BAD) {
     80            Nbad ++;
    7281            continue;
    7382          }
    74           Mmos  = getMmos  (m, i);
    75           if (isnan(Mmos)) {
    76             Nmos ++;
     83          // XXX allow REF stars (no Image Entry) to be included in the calculation this
     84          // should be optionally set, and should allow for REF stars to be downweighted by
     85          // more than their reported errors.  how such info is carried is unclear...
     86          if (getImageEntry (m, i) < 0) {
     87            Mcal = Mmos = Mgrid = 0;
     88          } else {
     89            Mcal  = getMcal  (m, i);
     90            if (isnan(Mcal)) {
     91              Ncal ++;
     92              continue;
     93            }
     94            Mmos  = getMmos  (m, i);
     95            if (isnan(Mmos)) {
     96              Nmos ++;
     97              continue;
     98            }
     99            Mgrid = getMgrid (m, i);
     100            if (isnan(Mgrid)) {
     101              Ngrid++;
     102              continue;
     103            }
     104          }
     105
     106          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     107          if (isnan(Msys)) {
     108            Nsys++;
    77109            continue;
    78110          }
    79           Mgrid = getMgrid (m, i);
    80           if (isnan(Mgrid)) {
    81             Ngrid++;
    82             continue;
     111          list[N] = Msys - Mcal - Mmos - Mgrid;
     112          dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
     113
     114          // tie down reference photometry if the -refcode (code) option is selected
     115          if (refPhotcode) {
     116            if (GetPhotcodeEquivCodebyCode(catalog[i].measure[m].photcode) == refPhotcode[0].equiv) {
     117              // increase the weight by a factor of 100:
     118              dlist[N] = 0.01*catalog[i].measure[m].dM;
     119            }
    83120          }
    84         }
    85 
    86         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    87         if (isnan(Msys)) {
    88           Nsys++;
    89           continue;
    90         }
    91         list[N] = Msys - Mcal - Mmos - Mgrid;
    92         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    93 
    94         if (refPhotcode) {
    95           if (GetPhotcodeEquivCodebyCode(catalog[i].measure[m].photcode) == refPhotcode[0].equiv) {
    96             // increase the weight by a factor of 100:
    97             dlist[N] = 0.01*catalog[i].measure[m].dM;
    98           }
    99         }
    100         N++;
    101       }
    102 
    103       // when performing the grid analysis, STAR_TOOFEW will be set to 1;
    104 
    105       if (N <= STAR_TOOFEW) { /* too few measurements */
    106         catalog[i].average[j].flags |= ID_STAR_FEW;
    107         Nfew ++;
    108       } else {
    109         catalog[i].average[j].flags &= ~ID_STAR_FEW;
    110       }
    111 
    112       liststats (list, dlist, N, &stats);
    113 
    114       catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    115       catalog[i].secfilt[PhotNsec*j+PhotSec].dM = stats.sigma;
    116       catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
     121          N++;
     122        }
     123
     124        // when performing the grid analysis, STAR_TOOFEW will be set to 1;
     125        // XXX DEP this makes no sense: need a separate flag for each secfilt
     126        if (N <= STAR_TOOFEW) { /* too few measurements */
     127          catalog[i].average[j].flags |= ID_STAR_FEW;
     128          Nfew ++;
     129        } else {
     130          catalog[i].average[j].flags &= ~ID_STAR_FEW;
     131        }       
     132
     133        liststats (list, dlist, N, &stats);
     134
     135        catalog[i].secfilt[Nsecfilt*j+Nsec].M  = stats.mean;
     136        catalog[i].secfilt[Nsecfilt*j+Nsec].dM = stats.sigma;
     137        catalog[i].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
     138      }
    117139    }
    118140  }
     
    129151  double *list, *dlist;
    130152  StatType stats;
     153  int Nsec, Nsecfilt, ecode;
     154
     155  Nsecfilt = GetPhotcodeNsecfilt ();
    131156
    132157  /* Nmeasure is now different, need to reallocate */
     
    142167  for (i = 0; i < Ncatalog; i++) {
    143168    for (j = 0; j < catalog[i].Naverage; j++) {
    144 
    145169      /* skip stars already calibrated */
    146170      if (catalog[i].found[j]) continue; 
    147171
    148       N = 0;
    149       m = catalog[i].average[j].measureOffset;
    150       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    151         if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
    152         // XXX allow REF stars (no Image Entry) to be included in the calculation this
    153         // should be optionally set, and should allow for REF stars to be downweighted by
    154         // more than their reported errors.  how such info is carried is unclear...
    155         if (getImageEntry (m, i) < 0) {
    156           Mcal = Mmos = Mgrid = 0;
    157         } else {
    158           Mcal  = getMcal  (m, i);
    159           if (isnan(Mcal)) continue;
    160           Mmos  = getMmos  (m, i);
    161           if (isnan(Mmos)) continue;
    162           Mgrid = getMgrid (m, i);
    163           if (isnan(Mgrid)) continue;
    164         }
    165 
    166         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    167         list[N] = Msys - Mcal - Mmos - Mgrid;
    168         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    169         N++;
    170       }
    171       if (N < 1) continue;
    172 
    173       liststats (list, dlist, N, &stats);
    174       if (mark) catalog[i].found[j] = TRUE;
    175 
    176       /* use sigma or error in dM for output? */
    177       catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    178       catalog[i].secfilt[PhotNsec*j+PhotSec].dM = MAX (stats.error, stats.sigma);
    179       catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
     172      int Ns;
     173      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     174        int thisCode = photcodes[Ns][0].code;
     175        Nsec = GetPhotcodeNsec(thisCode);
     176
     177        N = 0;
     178        m = catalog[i].average[j].measureOffset;
     179        for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     180          // skip measurements that do not match the current photcode
     181          ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
     182          if (ecode != thisCode) { continue; }
     183
     184          if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
     185
     186          // XXX allow REF stars (no Image Entry) to be included in the calculation this
     187          // should be optionally set, and should allow for REF stars to be downweighted by
     188          // more than their reported errors.  how such info is carried is unclear...
     189          if (getImageEntry (m, i) < 0) {
     190            Mcal = Mmos = Mgrid = 0;
     191          } else {
     192            Mcal  = getMcal  (m, i);
     193            if (isnan(Mcal)) continue;
     194            Mmos  = getMmos  (m, i);
     195            if (isnan(Mmos)) continue;
     196            Mgrid = getMgrid (m, i);
     197            if (isnan(Mgrid)) continue;
     198          }
     199
     200          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     201          list[N] = Msys - Mcal - Mmos - Mgrid;
     202          dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
     203          N++;
     204        }
     205        if (N < 1) continue;
     206
     207        liststats (list, dlist, N, &stats);
     208        if (mark) catalog[i].found[j] = TRUE;
     209
     210        /* use sigma or error in dM for output? */
     211        catalog[i].secfilt[Nsecfilt*j+Nsec].M  = stats.mean;
     212        catalog[i].secfilt[Nsecfilt*j+Nsec].dM = MAX (stats.error, stats.sigma);
     213        catalog[i].secfilt[Nsecfilt*j+Nsec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
     214      }
    180215    }
    181216  }
     
    209244  ALLOCATE (dlist, double, MAX (1, Nmax));
    210245
    211   Nsecfilt = catalog[0].Nsecfilt;
     246  Nsecfilt = GetPhotcodeNsecfilt ();
    212247
    213248# define PSFQUALSTATS 1
     
    227262          if (GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode) != Nc) continue;
    228263
    229           Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
     264          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    230265          if (isnan(Msys)) continue;
    231266
     
    346381void clean_stars (Catalog *catalog, int Ncatalog) {
    347382
    348   int i, j, Ndel, Nave, Ntot, mark;
     383  int i, j, Ndel, Nave, Ntot, mark, Ns;
    349384  float dM, Xm;
    350385  double Chisq, MaxScatter, MaxChisq;
     
    361396  ALLOCATE (slist, double, Ntot);
    362397  ALLOCATE (dlist, double, Ntot);
    363   for (i = Ntot = 0; i < Ncatalog; i++) {
    364     for (j = 0; j < catalog[i].Naverage; j++) {
    365       if (catalog[i].average[j].flags & STAR_BAD) continue;
    366       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    367       if (Xm == -1) continue;
    368       Chisq = pow (10.0, 0.01*Xm);
    369       xlist[Ntot] = Chisq;
    370       slist[Ntot] = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    371       dlist[Ntot] = 1;
    372       Ntot ++;
    373     }
    374   }
     398
     399  int Nsecfilt = GetPhotcodeNsecfilt ();
     400
     401  // eliminate bad stars using the stats for a single secfilt at a time
     402  // XXX DEP replace average.flags with secfilt flags
     403  for (Ns = 0; Ns < Nphotcodes; Ns ++) {
     404   
     405    int thisCode = photcodes[Ns][0].code;
     406    int Nsec = GetPhotcodeNsec(thisCode);
     407
     408    for (i = Ntot = 0; i < Ncatalog; i++) {
     409      for (j = 0; j < catalog[i].Naverage; j++) {
     410        if (catalog[i].average[j].flags & STAR_BAD) continue;
     411        Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     412        if (Xm == -1) continue;
     413        Chisq = pow (10.0, 0.01*Xm);
     414        xlist[Ntot] = Chisq;
     415        slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     416        dlist[Ntot] = 1;
     417        Ntot ++;
     418      }
     419    }
    375420 
    376   initstats ("MEAN");
    377   liststats (xlist, dlist, Ntot, &stats);
    378   MaxChisq = MAX (STAR_CHISQ, 2*stats.median);
    379   liststats (slist, dlist, Ntot, &stats);
    380   MaxScatter = MAX (STAR_SCATTER, 2*stats.median);
    381   fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq);
    382 
    383   Ndel = Nave = 0;
    384   for (i = 0; i < Ncatalog; i++) {
    385     for (j = 0; j < catalog[i].Naverage; j++) {
    386       dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    387       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    388       Chisq = pow (10.0, 0.01*Xm);
    389       mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
    390       if (mark) {
    391         catalog[i].average[j].flags |= ID_STAR_POOR;
    392         Ndel ++;
    393       } else {
    394         catalog[i].average[j].flags &= ~ID_STAR_POOR;
    395       }
    396       Nave ++;
    397     }
    398   }
    399   fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave);
    400   initstats (STATMODE);
     421    initstats ("MEAN");
     422    liststats (xlist, dlist, Ntot, &stats);
     423    MaxChisq = MAX (STAR_CHISQ, 2*stats.median);
     424    liststats (slist, dlist, Ntot, &stats);
     425    MaxScatter = MAX (STAR_SCATTER, 2*stats.median);
     426    fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq);
     427
     428    Ndel = Nave = 0;
     429    for (i = 0; i < Ncatalog; i++) {
     430      for (j = 0; j < catalog[i].Naverage; j++) {
     431        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     432        Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     433        Chisq = pow (10.0, 0.01*Xm);
     434        mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
     435        if (mark) {
     436          catalog[i].average[j].flags |= ID_STAR_POOR;
     437          Ndel ++;
     438        } else {
     439          catalog[i].average[j].flags &= ~ID_STAR_POOR;
     440        }
     441        Nave ++;
     442      }
     443    }
     444    fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave);
     445    initstats (STATMODE);
     446  }
    401447  free (xlist);
    402448  free (slist);
     
    416462  int Ncal, Nmos, Ngrid, Nfew;
    417463
     464  int Nsecfilt = GetPhotcodeNsecfilt ();
     465
    418466  if (VERBOSE) fprintf (stderr, "marking poor measures\n");
    419467  /* Nmeasure is now different, need to reallocate */
     
    437485    for (j = 0; j < catalog[i].Naverage; j++) {
    438486
    439       /* skip bad stars to prevent them from becoming good (on inner sample) */
    440       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    441 
    442       /* on final processing, skip stars already measured */
    443       if (final && catalog[i].found[j]) continue; 
    444 
    445       /* accumulate list of valid measurements */
    446       m = catalog[i].average[j].measureOffset;
    447       N = 0;
    448       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    449         /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
    450         Mcal  = getMcal  (m, i);
    451         if (isnan(Mcal)) { Ncal ++; continue; }
    452         Mmos  = getMmos  (m, i);
    453         if (isnan(Mmos)) { Nmos ++; continue; }
    454         Mgrid = getMgrid (m, i);
    455         if (isnan(Mgrid)) { Ngrid ++; continue; }
    456 
    457         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    458         list[N] = Msys - Mcal - Mmos - Mgrid;
    459         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    460         N++;
    461       }
    462       if (N <= TOOFEW) { Nfew ++; continue; }
    463 
    464       /* 3-sigma clip based on stats of inner 50% */
    465 
    466       // calculated mean of inner 50%
    467       initstats ("INNER_MEAN");
    468       liststats (list, dlist, N, &stats);
    469       stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */
    470 
    471       // ignore entries > 3sigma from inner mean
    472       for (k = m = 0; k < N; k++) {
    473         if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) {
    474           list[m] = list[k];
    475           m++;
    476         }
    477       }
    478       // recalculate the mean & sigma of the accepted measurements
    479       initstats ("MEAN");
    480       liststats (list, dlist, m, &stats);
    481       stats.sigma = MAX (MIN_ERROR, stats.sigma);
    482 
    483       /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */
    484       image_bad = IMAGE_BAD;
    485       IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
    486       m = catalog[i].average[j].measureOffset;
    487       N = 0;
    488       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    489         /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
    490         Mcal  = getMcal  (m, i);
    491         if (isnan(Mcal)) continue;
    492         Mmos  = getMmos  (m, i);
    493         if (isnan(Mmos)) continue;
    494         Mgrid = getMgrid (m, i);
    495         if (isnan(Mgrid)) continue;
    496 
    497         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    498         list[N] = Msys - Mcal - Mmos - Mgrid;
    499         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    500         ilist[N] = m;
    501         N++;
    502         Nave ++;
    503       }
    504       if (N < TOOFEW) continue;
    505 
    506       /* mark bad measures (> 3 sigma deviant) */
    507       for (k = 0; k < N; k++) {
    508         if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) {
    509           catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
    510           Ndel ++;
    511         }
    512       }
    513       IMAGE_BAD = image_bad;
     487      int Ns;
     488      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     489       
     490        /* on final processing, skip stars already measured */
     491        if (final && catalog[i].found[j]) continue; 
     492
     493        int thisCode = photcodes[Ns][0].code;
     494
     495        /* skip bad stars to prevent them from becoming good (on inner sample) */
     496        if (catalog[i].average[j].flags & STAR_BAD) continue; 
     497
     498        /* accumulate list of valid measurements */
     499        m = catalog[i].average[j].measureOffset;
     500        N = 0;
     501        for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     502          // skip measurements that do not match the current photcode
     503          int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
     504          if (ecode != thisCode) { continue; }
     505
     506          /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
     507          Mcal  = getMcal  (m, i);
     508          if (isnan(Mcal)) { Ncal ++; continue; }
     509          Mmos  = getMmos  (m, i);
     510          if (isnan(Mmos)) { Nmos ++; continue; }
     511          Mgrid = getMgrid (m, i);
     512          if (isnan(Mgrid)) { Ngrid ++; continue; }
     513
     514          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     515          list[N] = Msys - Mcal - Mmos - Mgrid;
     516          dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
     517          N++;
     518        }
     519        if (N <= TOOFEW) { Nfew ++; continue; }
     520
     521        /* 3-sigma clip based on stats of inner 50% */
     522
     523        // calculated mean of inner 50%
     524        initstats ("INNER_MEAN");
     525        liststats (list, dlist, N, &stats);
     526        stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */
     527
     528        // ignore entries > 3sigma from inner mean
     529        for (k = m = 0; k < N; k++) {
     530          if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) {
     531            list[m] = list[k];
     532            m++;
     533          }
     534        }
     535        // recalculate the mean & sigma of the accepted measurements
     536        initstats ("MEAN");
     537        liststats (list, dlist, m, &stats);
     538        stats.sigma = MAX (MIN_ERROR, stats.sigma);
     539
     540        /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */
     541        image_bad = IMAGE_BAD;
     542        IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
     543        m = catalog[i].average[j].measureOffset;
     544        N = 0;
     545        for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     546          // skip measurements that do not match the current photcode
     547          int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
     548          if (ecode != thisCode) { continue; }
     549
     550          /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
     551          Mcal  = getMcal  (m, i);
     552          if (isnan(Mcal)) continue;
     553          Mmos  = getMmos  (m, i);
     554          if (isnan(Mmos)) continue;
     555          Mgrid = getMgrid (m, i);
     556          if (isnan(Mgrid)) continue;
     557
     558          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
     559          list[N] = Msys - Mcal - Mmos - Mgrid;
     560          dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
     561          ilist[N] = m;
     562          N++;
     563          Nave ++;
     564        }
     565        if (N < TOOFEW) continue;
     566
     567        /* mark bad measures (> 3 sigma deviant) */
     568        for (k = 0; k < N; k++) {
     569          if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) {
     570            catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
     571            Ndel ++;
     572          }
     573        }
     574        IMAGE_BAD = image_bad;
     575      }
    514576    }
    515577  }
     
    567629}
    568630
     631// XXXX do this for all secfilt at once or one at a time?
    569632StatType statsStarX (Catalog *catalog, int Ncatalog) {
    570633
     
    574637  StatType stats;
    575638
     639  int Nsecfilt = GetPhotcodeNsecfilt ();
     640
    576641  Ntot = 0;
    577642  for (i = 0; i < Ncatalog; i++) {
     
    586651    for (j = 0; j < catalog[i].Naverage; j++) {
    587652
    588       /* calculate the average value for a single star */
    589       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    590 
    591       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    592       if (Xm == NAN_S_SHORT) continue;
    593       list[n] = pow (10.0, 0.01*Xm);
    594       dlist[n] = 1;
    595       n++;
     653      int Ns;
     654      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     655
     656        int thisCode = photcodes[Ns][0].code;
     657        int Nsec = GetPhotcodeNsec(thisCode);
     658
     659        /* calculate the average value for a single star */
     660        if (catalog[i].average[j].flags & STAR_BAD) continue; 
     661       
     662        Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     663        if (Xm == NAN_S_SHORT) continue;
     664        list[n] = pow (10.0, 0.01*Xm);
     665        dlist[n] = 1;
     666        n++;
     667      }
    596668    }
    597669  }
     
    611683  StatType stats;
    612684
     685  int Nsecfilt = GetPhotcodeNsecfilt ();
     686
    613687  Ntot = 0;
    614688  for (i = 0; i < Ncatalog; i++) {
     
    623697    for (j = 0; j < catalog[i].Naverage; j++) {
    624698
    625       /* calculate the average value for a single star */
    626       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    627 
    628       dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    629       list[n] = dM;
    630       dlist[n] = 1;
    631       n++;
     699      int Ns;
     700      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     701
     702        int thisCode = photcodes[Ns][0].code;
     703        int Nsec = GetPhotcodeNsec(thisCode);
     704
     705        /* calculate the average value for a single star */
     706        if (catalog[i].average[j].flags & STAR_BAD) continue; 
     707
     708        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     709        list[n] = dM;
     710        dlist[n] = 1;
     711        n++;
     712      }
    632713    }
    633714  }
     
    651732  ALLOCATE (Mlist, double, NBIN);
    652733
    653   for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
    654   bzero (Mlist, NBIN*sizeof(double));
    655   for (i = 0; i < Ncatalog; i++) {
    656     for (j = 0; j < catalog[i].Naverage; j++) {
    657       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    658       dMrel = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    659       bin = dMrel / 0.00025;
    660       bin = MAX (0, MIN (NBIN-1, bin));
    661       Mlist[bin] += 1.0;
    662     }
    663   }
    664 
    665   plot_defaults (&graphdata);
    666   graphdata.style = 1;
    667   plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT);
    668 
     734  int Nsecfilt = GetPhotcodeNsecfilt ();
     735
     736  int Ns;
     737  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     738
     739    int thisCode = photcodes[Ns][0].code;
     740    int Nsec = GetPhotcodeNsec(thisCode);
     741
     742    for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
     743    bzero (Mlist, NBIN*sizeof(double));
     744    for (i = 0; i < Ncatalog; i++) {
     745      for (j = 0; j < catalog[i].Naverage; j++) {
     746        if (catalog[i].average[j].flags & STAR_BAD) continue; 
     747        dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     748        bin = dMrel / 0.00025;
     749        bin = MAX (0, MIN (NBIN-1, bin));
     750        Mlist[bin] += 1.0;
     751      }
     752    }
     753
     754    plot_defaults (&graphdata);
     755    graphdata.style = 1;
     756    plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT);
     757  }
    669758  free (xlist);
    670759  free (Mlist);
     
    678767  Graphdata graphdata;
    679768
     769  int Nsecfilt = GetPhotcodeNsecfilt ();
     770
    680771  Ntotal = 0;
    681772  for (i = 0; i < Ncatalog; i++) Ntotal += catalog[i].Naverage;
     
    684775  ALLOCATE (ylist, double, Ntotal);
    685776
    686   N = 0;
    687   for (i = 0; i < Ncatalog; i++) {
    688     for (j = 0; j < catalog[i].Naverage; j++) {
    689       if (catalog[i].average[j].flags & STAR_BAD) continue;
    690       xlist[N] = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    691       value    = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    692       if (value == NAN_S_SHORT) continue;
    693       ylist[N] = 0.01*value;
    694       N++;
    695     }
    696   }
    697 
    698   plot_defaults (&graphdata);
    699   graphdata.ymin = -3.0;
    700   plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT);
     777  int Ns;
     778  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     779
     780    int thisCode = photcodes[Ns][0].code;
     781    int Nsec = GetPhotcodeNsec(thisCode);
     782
     783    N = 0;
     784    for (i = 0; i < Ncatalog; i++) {
     785      for (j = 0; j < catalog[i].Naverage; j++) {
     786        if (catalog[i].average[j].flags & STAR_BAD) continue;
     787        xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
     788        value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     789        if (value == NAN_S_SHORT) continue;
     790        ylist[N] = 0.01*value;
     791        N++;
     792      }
     793    }
     794
     795    plot_defaults (&graphdata);
     796    graphdata.ymin = -3.0;
     797    plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT);
     798  }
     799
    701800  free (xlist);
    702801  free (ylist);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/bcatalog.c

    r31258 r31261  
    66 
    77  off_t i, j, offset;
    8   int ecode;
     8  int ecode, found, Ns;
    99  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
    1010  float mag;
    1111  int Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew, Ngalaxy, Npsfqf;
    1212
    13   // XXX PhotNsec as a global is a bad idea; either get it from catalog
    14   // or get it from:
    15   // Nsecfilt = GetPhotcodeNsecfilt ();
    16   // assert (catalog[0].Nsecfilt == Nsecfilt);
     13  int Nsecfilt = GetPhotcodeNsecfilt ();
     14  assert (Nsecfilt == catalog[0].Nsecfilt);
    1715
    1816  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    2119  NMEASURE = 1000;
    2220  ALLOCATE (subcatalog[0].average, Average, NAVERAGE);
    23   ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*PhotNsec);
     21  ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
    2422  ALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
    2523  Nmeasure = Naverage = 0;
     
    3432    subcatalog[0].average[Naverage] = catalog[0].average[i];
    3533    subcatalog[0].average[Naverage].measureOffset = Nmeasure;
    36     for (j = 0; j < PhotNsec; j++) {
    37       subcatalog[0].secfilt[PhotNsec*Naverage+j] = catalog[0].secfilt[PhotNsec*i+j];
     34    for (j = 0; j < Nsecfilt; j++) {
     35      subcatalog[0].secfilt[Nsecfilt*Naverage+j] = catalog[0].secfilt[Nsecfilt*i+j];
    3836    }
    3937
    4038    if (RESET) {
    41       subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].M  = NAN;
    42       subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].dM = NAN;
    43       subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW;
    44       subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR;
     39      int Ns;
     40      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     41
     42        int thisCode = photcodes[Ns][0].code;
     43        int Nsec = GetPhotcodeNsec(thisCode);
     44
     45        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M  = NAN;
     46        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM = NAN;
     47        subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW;
     48        subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR;
     49      }
    4550    }
    4651
     
    5459      /* select measurements by photcode */
    5560      ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode);
    56       if (ecode != photcode[0].code) { Ncode ++; continue; }
     61      found = FALSE;
     62      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     63        if (ecode == photcodes[Ns][0].code) found = TRUE;
     64      }
     65      if (!found) {
     66        Ncode ++;
     67        continue;
     68      }
    5769
    5870      /* select measurements by time */
     
    129141      NAVERAGE += 50;
    130142      REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
    131       REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*PhotNsec);
     143      REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
    132144    }
    133145  }
    134146  REALLOCATE (subcatalog[0].average, Average, MAX (Naverage, 1));
    135147  REALLOCATE (subcatalog[0].measure, Measure, MAX (Nmeasure, 1));
    136   REALLOCATE (subcatalog[0].secfilt, SecFilt, PhotNsec*MAX (Naverage, 1));
     148  REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1));
    137149  subcatalog[0].Naverage = Naverage;
    138150  subcatalog[0].Nmeasure = Nmeasure;
    139151  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    140152  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
    141   assert (PhotNsec == catalog[0].Nsecfilt);
    142153
    143154  // limit the total number of stars in the catalog
     
    161172  double Rmin, Rmax, Dmin, Dmax;
    162173
     174  int Nsecfilt = GetPhotcodeNsecfilt ();
     175
    163176  gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
    164177  gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
     
    205218  // allocate the output data
    206219  ALLOCATE (tmpcatalog.average, Average, Nmax);
    207   ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * PhotNsec);
     220  ALLOCATE (tmpcatalog.secfilt, SecFilt, Nmax * Nsecfilt);
    208221  ALLOCATE (tmpcatalog.measure, Measure, NMEASURE);
    209222
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/initialize.c

    r31258 r31261  
    1313    N = UserPatchSelect ? 1 : 2;
    1414
     15# if (0)
     16    // XXX DEP
    1517    if ((photcode = GetPhotcodebyName (argv[N])) == NULL) {
    1618      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
     
    2123      exit (1);
    2224    }
     25    // PhotSec is used to select the single average photcode being processed
    2326    PhotSec = GetPhotcodeNsec (photcode[0].code);
     27# endif
     28
     29    Nphotcodes = 0;
     30    photcodes = NULL;
     31    int NPHOTCODES = 10;
     32    ALLOCATE (photcodes, PhotCode *, NPHOTCODES);
     33
     34    /* parse the comma-separated list of photcodesKeep */
     35    char *myList = strcreate(argv[N]);
     36    char *list = myList;
     37    char *codename = NULL;
     38    char *ptr = NULL;
     39    while ((codename = strtok_r (list, ",", &ptr)) != NULL) {
     40      list = NULL; // pass NULL on successive strtok_r calls
     41      fprintf (stderr, "PHOTCODE LIST: %s\n", myList);
     42      fprintf (stderr, "codename: %s\n", codename);
     43      if ((photcodes[Nphotcodes] = GetPhotcodebyName (codename)) == NULL) {
     44        fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", codename);
     45        exit (1);
     46      }
     47      if (photcodes[Nphotcodes][0].type != PHOT_SEC) {
     48          fprintf (stderr, "photcode %s is not an filter type (SEC)\n", codename);
     49          exit (1);
     50      }
     51      Nphotcodes ++;
     52      CHECK_REALLOCATE (photcodes, PhotCode *, NPHOTCODES, Nphotcodes, 10);
     53    }
    2454  }
    25 
    26   PhotNsec = GetPhotcodeNsecfilt ();
     55  // XXX DEP PhotNsec = GetPhotcodeNsecfilt ();
     56  if (USE_GRID && (Nphotcodes > 1)) {
     57    fprintf (stderr, "grid correction analysis currently can only operate on a single photcode\n");
     58    exit (1);
     59  }
    2760
    2861  initstats (STATMODE);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/plot_scatter.c

    r27435 r31261  
    1818  ALLOCATE (ilist, double, Ntot);
    1919
    20   N = 0;
    21   for (i = 0; i < Ncatalog; i++) {
    22     for (j = 0; j < catalog[i].Naverage; j++) {
     20  int Nsecfilt = GetPhotcodeNsecfilt ();
    2321
    24       /* calculate the average value for a single star */
    25       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    26       m = catalog[i].average[j].measureOffset;
     22  int Ns;
     23  for (Ns = 0; Ns < Nphotcodes; Ns++) {
    2724
    28       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    29         if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
    30         Mcal = getMcal  (m, i);
    31         if (isnan(Mcal)) continue;
    32         Mmos = getMmos  (m, i);
    33         if (isnan(Mmos)) continue;
    34         Mgrid = getMgrid (m, i);
    35         if (isnan(Mgrid)) continue;
     25    int thisCode = photcodes[Ns][0].code;
     26    int Nsec = GetPhotcodeNsec(thisCode);
    3627
    37         Mrel = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    38         xlist[N] = Mrel;
    39         ylist[N] = PhotSys  (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]) - Mcal - Mmos - Mgrid - Mrel;
    40         ilist[N] = PhotInst (&catalog[i].measure[m]);
    41         N++;
    42       }
     28    N = 0;
     29    for (i = 0; i < Ncatalog; i++) {
     30        for (j = 0; j < catalog[i].Naverage; j++) {
     31
     32            /* calculate the average value for a single star */
     33            if (catalog[i].average[j].flags & STAR_BAD) continue; 
     34            m = catalog[i].average[j].measureOffset;
     35
     36            for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     37                // skip measurements that do not match the current photcode
     38                int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
     39                if (ecode != thisCode) { continue; }
     40
     41                if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
     42                Mcal = getMcal  (m, i);
     43                if (isnan(Mcal)) continue;
     44                Mmos = getMmos  (m, i);
     45                if (isnan(Mmos)) continue;
     46                Mgrid = getMgrid (m, i);
     47                if (isnan(Mgrid)) continue;
     48
     49                Mrel = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
     50                xlist[N] = Mrel;
     51                ylist[N] = PhotSys  (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel;
     52                ilist[N] = PhotInst (&catalog[i].measure[m]);
     53                N++;
     54            }
     55        }
    4356    }
     57
     58    plot_defaults (&graphdata);
     59    graphdata.xmin = PlotMmin;
     60    graphdata.xmax = PlotMmax;
     61    graphdata.ymin = PlotdMmin;
     62    graphdata.ymax = PlotdMmax;
     63    plot_list (&graphdata, xlist, ylist, N, "mag vs dmag", "%s.Mag.png", OUTROOT);
     64
     65    plot_defaults (&graphdata);
     66    graphdata.ymin = PlotdMmin;
     67    graphdata.ymax = PlotdMmax;
     68    plot_list (&graphdata, ilist, ylist, N, "imag vs dmag", "%s.iMag.png", OUTROOT);
    4469  }
    45 
    46   plot_defaults (&graphdata);
    47   graphdata.xmin = PlotMmin;
    48   graphdata.xmax = PlotMmax;
    49   graphdata.ymin = PlotdMmin;
    50   graphdata.ymax = PlotdMmax;
    51   plot_list (&graphdata, xlist, ylist, N, "mag vs dmag", "%s.Mag.png", OUTROOT);
    52 
    53   plot_defaults (&graphdata);
    54   graphdata.ymin = PlotdMmin;
    55   graphdata.ymax = PlotdMmax;
    56   plot_list (&graphdata, ilist, ylist, N, "imag vs dmag", "%s.iMag.png", OUTROOT);
    5770  free (xlist);
    5871  free (ylist);
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/select_images.c

    r31258 r31261  
    119119    /* exclude images by photcode */
    120120    ecode = GetPhotcodeEquivCodebyCode (timage[i].photcode);
    121     if (ecode != photcode[0].code) continue;
     121    found = FALSE;
     122    int Ns;
     123    for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     124        if (ecode == photcodes[Ns][0].code) found = TRUE;
     125    }
     126    if (!found) continue;
    122127
    123128    /* exclude images by time */
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setExclusions.c

    r28241 r31261  
    44
    55  off_t i, j, k, m, Narea, Nnocal, Ngood;
    6   int ecode;
     6  int ecode, found, Ns;
    77  Coords *coords;
    88  double r, d, x, y;
     
    1616        /* select measurements by photcode */
    1717        ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
    18         if (ecode != photcode[0].code) goto mark_nocal;
     18        found = FALSE;
     19        for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     20            if (ecode == photcodes[Ns][0].code) found = TRUE;
     21        }
     22        if (!found) goto mark_nocal;
    1923       
    2024        /* select measurements by time */
  • branches/eam_branches/ipp-20110404/Ohana/src/relphot/src/setMrelFinal.c

    r29001 r31261  
    99  if (RESET) {
    1010
    11     for (i = 0; i < catalog[0].Naverage; i++) {
    12       catalog[0].secfilt[PhotNsec*i+PhotSec].M  = NAN;
    13       catalog[0].secfilt[PhotNsec*i+PhotSec].dM = NAN;
    14       catalog[0].secfilt[PhotNsec*i+PhotSec].Xm = NAN_S_SHORT;
     11    int Nsecfilt = GetPhotcodeNsecfilt ();
    1512
    16       m = catalog[0].average[i].measureOffset;
    17       for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
     13    int Ns;
     14    for (Ns = 0; Ns < Nphotcodes; Ns++) {
    1815       
    19         /* select measurements by photcode */
    20         ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
    21         if (ecode != photcode[0].code) continue;
     16      int thisCode = photcodes[Ns][0].code;
     17      int Nsec = GetPhotcodeNsec(thisCode);
     18
     19      for (i = 0; i < catalog[0].Naverage; i++) {
     20        catalog[0].secfilt[Nsecfilt*i+Nsec].M  = NAN;
     21        catalog[0].secfilt[Nsecfilt*i+Nsec].dM = NAN;
     22        catalog[0].secfilt[Nsecfilt*i+Nsec].Xm = NAN_S_SHORT;
     23
     24        m = catalog[0].average[i].measureOffset;
     25        for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
    2226       
    23         /* select measurements by time */
    24         if (TimeSelect) {
    25           if (catalog[0].measure[m].t < TSTART) continue;
    26           if (catalog[0].measure[m].t > TSTOP) continue;
     27          // skip measurements that do not match the current photcode
     28          ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
     29          if (ecode != thisCode) { continue; }
     30
     31          /* select measurements by time */
     32          if (TimeSelect) {
     33            if (catalog[0].measure[m].t < TSTART) continue;
     34            if (catalog[0].measure[m].t > TSTOP) continue;
     35          }
     36       
     37          catalog[0].measure[m].Mcal = 0;
     38          catalog[0].measure[m].dbFlags &= 0xff00;
     39          catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
     40          catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
     41          catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA;
     42          catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
    2743        }
    28        
    29         catalog[0].measure[m].Mcal = 0;
    30         catalog[0].measure[m].dbFlags &= 0xff00;
    31         catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
    32         catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    33         catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA;
    34         catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
    3544      }
    3645    }
     
    6877
    6978  off_t i, k, m;
    70   int ecode;
     79  int ecode, found, Ns;
    7180  off_t Ntot, Ntry, Nkeep, Nskip;
    7281  float mag;
     
    95104      /* skipped via NOCAL, don't mark as skipped */
    96105      ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
    97       if (ecode != photcode[0].code) continue;
     106      found = FALSE;
     107      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     108        if (ecode == photcodes[Ns][0].code) found = TRUE;
     109      }
     110      if (!found) continue;
    98111
    99112      /* skip measurements by time range */
Note: See TracChangeset for help on using the changeset viewer.