IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31606


Ignore:
Timestamp:
Jun 6, 2011, 1:56:22 PM (15 years ago)
Author:
watersc1
Message:

merge from trunk before working on new stacking code

Location:
branches/czw_branch/20110406
Files:
189 edited
5 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406

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

    r28190 r31606  
    7676        mkdir -p $(DESTLIB)
    7777        mkdir -p $(DESTBIN)
    78         for i in $(LIBS); do make $$i.install || exit 1; done
     78        for i in $(LIBS); do $(MAKE) $$i.install || exit 1; done
    7979        chmod +x ohana-config
    8080        cp -f ohana-config $(DESTBIN)/
    8181
    8282bins:
    83         for i in $(PROGRAM); do make $$i; done
     83        for i in $(PROGRAM); do $(MAKE) $$i; done
    8484
    8585all:
    86         make libs || exit 1
    87         for i in $(PROGRAM); do make $$i || exit 1; done
     86        $(MAKE) libs || exit 1
     87        for i in $(PROGRAM); do $(MAKE) $$i || exit 1; done
    8888
    8989extras:
    90         for i in $(EXTRAS); do make $$i || exit 1; done
     90        for i in $(EXTRAS); do $(MAKE) $$i || exit 1; done
    9191
    9292pantasks:
    93         make libs || exit 1
    94         cd src/opihi; make pclient.install && exit 1
    95         cd src/opihi; make pcontrol.install && exit 1
    96         cd src/opihi; make pantasks.install && exit 1
     93        $(MAKE) libs || exit 1
     94        cd src/opihi; $(MAKE) pclient.install && exit 1
     95        cd src/opihi; $(MAKE) pcontrol.install && exit 1
     96        cd src/opihi; $(MAKE) pantasks.install && exit 1
    9797
    9898mana:
    99         make libs
    100         make kapa2.install
    101         cd src/opihi; make mana.install && exit 1
     99        $(MAKE) libs
     100        $(MAKE) kapa2.install
     101        cd src/opihi; $(MAKE) mana.install && exit 1
    102102
    103103dvoshell:
    104         make libs
    105         make kapa2.install
    106         cd src/opihi; make dvo.install && exit 1
     104        $(MAKE) libs
     105        $(MAKE) kapa2.install
     106        cd src/opihi; $(MAKE) dvo.install && exit 1
    107107
    108108clean:
    109109        @if [ "$(ARCH)" = "" ]; then echo ""; echo " *** please define ARCH ***"; echo; exit 1; fi
    110         for i in $(LIBS); do make $$i.clean || exit 1; done
    111         for i in $(PROGRAM); do make $$i.clean || exit 1; done
    112         for i in $(EXTRAS); do make $$i.clean || exit 1; done
     110        for i in $(LIBS); do $(MAKE) $$i.clean || exit 1; done
     111        for i in $(PROGRAM); do $(MAKE) $$i.clean || exit 1; done
     112        for i in $(EXTRAS); do $(MAKE) $$i.clean || exit 1; done
    113113        @rm -f `find . -name .mana`
    114114        @rm -f `find . -name .dvo`
     
    117117dist:
    118118        @if [ "$(ARCH)" = "" ]; then echo ""; echo " *** please define ARCH ***"; echo; exit 1; fi
    119         for i in $(LIBS); do make $$i.dist || exit 1; done
    120         for i in $(PROGRAM); do make $$i.dist || exit 1; done
     119        for i in $(LIBS); do $(MAKE) $$i.dist || exit 1; done
     120        for i in $(PROGRAM); do $(MAKE) $$i.dist || exit 1; done
    121121        @echo -n -e "\0033]0; *** Ohana: done $@ *** \0007" \
    122122
    123123install:
    124124        @if [ "$(ARCH)" = "" ]; then echo ""; echo " *** please define ARCH ***"; echo; exit 1; fi
    125         for i in $(LIBS); do make $$i.install || exit 1; done
    126         for i in $(PROGRAM); do make $$i.install || exit 1; done
     125        for i in $(LIBS); do $(MAKE) $$i.install || exit 1; done
     126        for i in $(PROGRAM); do $(MAKE) $$i.install || exit 1; done
    127127        @echo -n -e "\0033]0; *** Ohana: done $@ *** \0007" \
    128128
    129129install.extras:
    130         for i in $(EXTRAS); do make $$i.install || exit 1; done
     130        for i in $(EXTRAS); do $(MAKE) $$i.install || exit 1; done
    131131        @echo -n -e "\0033]0; *** Ohana: done $@ *** \0007" \
    132132
     
    135135        @if [ -d "src/$@" ]; then \
    136136          echo -n -e "\0033]0; *** Ohana: $@ *** \0007"; \
    137           (cd src/$@ && make); \
     137          (cd src/$@ && $(MAKE)); \
    138138        fi
    139139        @echo -n -e "\0033]0; *** Ohana: done $@ *** \0007" \
     
    142142        @echo -n -e "\0033]0; *** Ohana: $@ *** \0007" \
    143143        mkdir -p bin/$(ARCH)
    144         if [ -d "src/$*" ]; then (cd src/$* && make install); fi
     144        if [ -d "src/$*" ]; then (cd src/$* && $(MAKE) install); fi
    145145
    146146%.clean:
    147         if [ -d "src/$*" ]; then (cd src/$* && make clean); fi
     147        if [ -d "src/$*" ]; then (cd src/$* && $(MAKE) clean); fi
    148148
    149149%.dist:
    150         (cd src/$* && make dist)
     150        (cd src/$* && $(MAKE) dist)
  • branches/czw_branch/20110406/Ohana/src/addstar/Makefile

    r29938 r31606  
    267267
    268268%.install:
    269         make $(DESTBIN)/$*
     269        $(MAKE) $(DESTBIN)/$*
    270270
    271271install:
    272         for i in $(INSTALL); do make $$i.install || exit; done
     272        for i in $(INSTALL); do $(MAKE) $$i.install || exit; done
  • branches/czw_branch/20110406/Ohana/src/dvomerge/Makefile

    r29938 r31606  
    108108
    109109%.install:
    110         make $(DESTBIN)/$*
     110        $(MAKE) $(DESTBIN)/$*
    111111
    112112install:
    113         for i in $(INSTALL); do make $$i.install || exit; done
     113        for i in $(INSTALL); do $(MAKE) $$i.install || exit; done
  • branches/czw_branch/20110406/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r29938 r31606  
    202202    if (newID == 0) {
    203203      fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n",  oldID);
    204       exit (2);
     204      // exit (2);
    205205    }
    206206    catalog[0].measure[i].imageID = newID;
  • branches/czw_branch/20110406/Ohana/src/dvomerge/src/dvoverify.c

    r31160 r31606  
    148148int VerifyTableFile (char *filename) {
    149149
    150   int status;
     150  int status, Next;
    151151  off_t Nbytes;
    152152  Header header;
     
    205205  // scan all extentions
    206206  Nbytes = 0;
     207  Next = -1;
    207208  if (DEBUG) fprintf (stderr, "sizes: ("OFF_T_FMT" vs "OFF_T_FMT")\n", Nbytes, fileStats.st_size);
    208209  while (Nbytes < fileStats.st_size) {
     
    210211    // Check on the PHU
    211212    if (!gfits_fread_header (file, &header)) {
    212       fprintf (stderr, "unable to read PHU header for %s\n", filename);
     213      if (Next == -1) {
     214        fprintf (stderr, "unable to read PHU header for %s\n", filename);
     215      } else {
     216        fprintf (stderr, "unable to read header for %s, extension %d (or file has excess bytes)\n", filename, Next);
     217      }
    213218      fclose(file);
    214219      return (FALSE);
     
    243248      }
    244249    }
     250    Next ++;
    245251  }
    246252  if (DEBUG) fprintf (stderr, "file is good: %s\n", filename);
  • branches/czw_branch/20110406/Ohana/src/dvosplit/Makefile

    r15743 r31606  
    4343
    4444%.install:
    45         make $(DESTBIN)/$*
     45        $(MAKE) $(DESTBIN)/$*
    4646
    4747install:
    48         for i in $(INSTALL); do make $$i.install || exit; done
     48        for i in $(INSTALL); do $(MAKE) $$i.install || exit; done
  • branches/czw_branch/20110406/Ohana/src/imregister/Makefile

    r16040 r31606  
    185185%.rebuild :
    186186        rm -f $(BIN)/$*.$(ARCH)
    187         make $(DESTBIN)/$*
     187        $(MAKE) $(DESTBIN)/$*
    188188
    189189%.install:
    190         make $(DESTBIN)/$*
     190        $(MAKE) $(DESTBIN)/$*
    191191
    192192install:
    193         for i in $(INSTALL); do make $$i.install || exit; done
     193        for i in $(INSTALL); do $(MAKE) $$i.install || exit; done
  • branches/czw_branch/20110406/Ohana/src/kapa2/src/DrawObjects.c

    r29539 r31606  
    11# include "Ximage.h"
    22
    3 # define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
    4 # define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
    5 # define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1+0.5), (int)(Y1+0.5), (int)(X2+0.5), (int)(Y2+0.5)))
    6 # define DrawCircle(X,Y,R) (XDrawArc (graphic->display, graphic->window, graphic->gc, (int)(X-R+0.5), (int)(Y-R+0.5), abs(2*R+0.5), abs(2*R+0.5), 0, 23040))
     3# define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
     4# define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
     5# define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
     6# 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))
    77
    88# define CONNECT 0
    99# define HISTOGRAM 1
    1010# define POINTS 2
     11
     12# define XCENTER 0.0
     13# define YCENTER 0.0
     14# define CAPSTYLE CapButt
     15# define JOINSTYLE JoinMiter
    1116
    1217static Graphic *graphic;
     
    3439  // this function calls all of the supporting Draw... functions below
    3540  graphic = GetGraphic();
    36 
    37   lweight = MAX (0, MIN (10, object[0].lweight));
     41 
     42  lweight = MAX (1, MIN (10, object[0].lweight));
     43
     44  /** some notes on drawing lines in X:
     45
     46      "In general, drawing a thin line will be faster than drawing a wide line of width
     47      one. However, because of their different drawing algorithms, thin lines may not mix
     48      well aesthetically with wide lines. If it is desirable to obtain precise and uniform
     49      results across all displays, a client should always use a line-width of one rather
     50      than a line-width of zero."  -- http://www.hpc.unimelb.edu.au/nec/g1ae02e/chap7.html
     51
     52  */
    3853
    3954  /* set line type */
    4055  switch (object[0].ltype) {
    4156    case 0:
    42       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
     57      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CAPSTYLE, JOINSTYLE);
    4358      break;
    4459    case 1:
    4560      XSetDashes (graphic->display, graphic->gc, 100, dash, 2);
    46       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CapNotLast, JoinMiter);
     61      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    4762      break;
    4863    case 2:
    4964      XSetDashes (graphic->display, graphic->gc, 10, dot, 2);
    50       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CapNotLast, JoinMiter);
     65      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    5166      break;
    5267    default:
    53       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
     68      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CAPSTYLE, JOINSTYLE);
    5469      break;
    5570  }
     
    7691  }
    7792
    78   XSetLineAttributes (graphic->display, graphic->gc, 0, LineSolid, CapNotLast, JoinMiter);
     93  XSetLineAttributes (graphic->display, graphic->gc, 0, LineSolid, CAPSTYLE, JOINSTYLE);
    7994  XSetForeground (graphic->display, graphic->gc, graphic->fore);
    8095  return (TRUE);
     
    111126  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
    112127  if (i >= object[0].Npts) return;
    113   sx0 = x[i]*mxi + y[i]*mxj + bx;
    114   sy0 = x[i]*myi + y[i]*myj + by;
     128  sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     129  sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
    115130
    116131  for (i++; i < object[0].Npts; i++) {
    117132    if (!(finite(x[i]) && finite(y[i]))) continue;
    118     sx1 = x[i]*mxi + y[i]*mxj + bx;
    119     sy1 = x[i]*myi + y[i]*myj + by;
     133    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     134    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    120135   
    121136    ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     
    213228
    214229  /* first valid data point */
    215   sx0 = x[i]*mxi + y[i]*mxj + bx;
    216   sy0 = x[i]*myi + y[i]*myj + by;
     230  sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     231  sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
    217232  sx0 = MIN (MAX (sx0, X0), X1);
    218233  sy0 = MAX (MIN (sy0, Y0), Y1);
     
    223238
    224239  /* second valid data point */
    225   sx1 = x[i]*mxi + y[i]*mxj + bx;
    226   sy1 = x[i]*myi + y[i]*myj + by;
     240  sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     241  sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    227242  sx1 = MIN (MAX (sx1, X0), X1);
    228243  sy1 = MAX (MIN (sy1, Y0), Y1);
     
    246261  for (i++; i < object[0].Npts; i++) {
    247262    if (!(finite(x[i]) && finite(y[i]))) continue;
    248     sx1 = x[i]*mxi + y[i]*mxj + bx;
    249     sy1 = x[i]*myi + y[i]*myj + by;
     263    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     264    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    250265    sx1 = MIN (MAX (sx1, X0), X1);
    251266    sy1 = MAX (MIN (sy1, Y0), Y1);
     
    298313
    299314  /* first valid data point */
    300   sx0 = x[i]*mxi + y[i]*mxj + bx;
    301   sy0 = x[i]*myi + y[i]*myj + by;
     315  sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     316  sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
    302317  sx0 = MIN (MAX (sx0, X0), X1);
    303318  sy0 = MAX (MIN (sy0, Y0), Y1);
     
    308323
    309324  /* second valid data point */
    310   sx1 = x[i]*mxi + y[i]*mxj + bx;
    311   sy1 = x[i]*myi + y[i]*myj + by;
     325  sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     326  sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    312327  sx1 = MIN (MAX (sx1, X0), X1);
    313328  sy1 = MAX (MIN (sy1, Y0), Y1);
     
    330345  for (i++; i < object[0].Npts; i++) {
    331346    if (!(finite(x[i]) && finite(y[i]))) continue;
    332     sx1 = x[i]*mxi + y[i]*mxj + bx;
    333     sy1 = x[i]*myi + y[i]*myj + by;
     347    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     348    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    334349    sx1 = MIN (MAX (sx1, X0), X1);
    335350    sy1 = MAX (MIN (sy1, Y0), Y1);
     
    356371  float *x, *y, *z;
    357372  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
    358   double sx, sy, d, sx1, sy1, sx2, sy2;
     373  int sx, sy, sx1, sy1, sx2, sy2, d, D;
    359374 
    360375  mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);
     
    375390    d = 0.5 * (graphic->dx + graphic->dy) * 0.01;
    376391    x = object[0].x; y = object[0].y; z = object[0].z;
     392
    377393    if (object[0].ptype == 0) { /* filled box */
    378394      for (i = 0; i < object[0].Npts; i++) {
    379395        if (!(finite(x[i]) && finite(y[i]))) continue;
    380         sx = x[i]*mxi + y[i]*mxj + bx;
    381         sy = x[i]*myi + y[i]*myj + by;
    382         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    383             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    384         {
    385           FillRectangle (sx - d*z[i], sy - d*z[i], 2*d*z[i], 2*d*z[i]);
     396        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     397        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     398        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     399            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     400        {
     401          D = d*z[i];
     402          FillRectangle (sx - D, sy - D, 2*D + 1, 2*D + 1);
    386403        }
    387404      }
     
    390407      for (i = 0; i < object[0].Npts; i++) {
    391408        if (!(finite(x[i]) && finite(y[i]))) continue;
    392         sx = x[i]*mxi + y[i]*mxj + bx;
    393         sy = x[i]*myi + y[i]*myj + by;
    394         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    395             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    396         {
    397           DrawRectangle (sx - d*z[i], sy - d*z[i], 2*d*z[i], 2*d*z[i]);
     409        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     410        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     411        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     412            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     413        {
     414          D = d*z[i];
     415          DrawRectangle (sx - D, sy - D, 2*D, 2*D);
    398416        }
    399417      }
     
    402420      for (i = 0; i < object[0].Npts; i++) {
    403421        if (!(finite(x[i]) && finite(y[i]))) continue;
    404         sx = x[i]*mxi + y[i]*mxj + bx;
    405         sy = x[i]*myi + y[i]*myj + by;
    406         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    407             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    408         {
    409           DrawLine (sx - d*z[i], sy, sx + d*z[i] + 1, sy);
    410           DrawLine (sx, sy - d*z[i], sx, sy + d*z[i] + 1);
     422        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     423        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     424        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     425            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     426        {
     427          D = d*z[i];
     428          DrawLine (sx - D, sy, sx + D + 1, sy);
     429          DrawLine (sx, sy - D, sx, sy + D + 1);
    411430        }
    412431      }
     
    415434      for (i = 0; i < object[0].Npts; i++) {
    416435        if (!(finite(x[i]) && finite(y[i]))) continue;
    417         sx = x[i]*mxi + y[i]*mxj + bx;
    418         sy = x[i]*myi + y[i]*myj + by;
    419         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    420             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    421         {
    422           DrawLine (sx + d*z[i] + 1, sy - d*z[i] - 1, sx - d*z[i], sy + d*z[i]);
    423           DrawLine (sx - d*z[i], sy - d*z[i], sx + d*z[i] + 1, sy + d*z[i] + 1);
     436        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     437        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     438        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     439            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     440        {
     441          D = d*z[i];
     442          DrawLine (sx - D, sy + D, sx + D + 1, sy - D - 1);
     443          DrawLine (sx - D, sy - D, sx + D + 1, sy + D + 1);
    424444        }
    425445      }
     
    429449      for (i = 0; i < object[0].Npts; i++) {
    430450        if (!(finite(x[i]) && finite(y[i]))) continue;
    431         sx = x[i]*mxi + y[i]*mxj + bx;
    432         sy = x[i]*myi + y[i]*myj + by;
    433         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    434             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    435         {
    436           points[0].x = sx - d*z[i];  points[0].y = sy + 0.58*d*z[i]; 
    437           points[1].x = sx + d*z[i];  points[1].y = sy + 0.58*d*z[i]; 
    438           points[2].x = sx;           points[2].y = sy - 1.15*d*z[i]; 
    439           points[3].x = sx - d*z[i];  points[3].y = sy + 0.58*d*z[i]; 
     451        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     452        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     453        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     454            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     455        {
     456          D = d*z[i];
     457          points[0].x = sx - D;  points[0].y = sy + 0.58*D; 
     458          points[1].x = sx + D;  points[1].y = sy + 0.58*D; 
     459          points[2].x = sx;      points[2].y = sy - 1.15*D; 
     460          points[3].x = sx - D;  points[3].y = sy + 0.58*D; 
    440461          XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
    441462        }
     
    445466      for (i = 0; i < object[0].Npts; i++) {
    446467        if (!(finite(x[i]) && finite(y[i]))) continue;
    447         sx = x[i]*mxi + y[i]*mxj + bx;
    448         sy = x[i]*myi + y[i]*myj + by;
    449         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    450             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    451         {
    452           DrawLine (sx - d*z[i], sy + 0.58*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
    453           DrawLine (sx + d*z[i], sy + 0.58*d*z[i], sx,          sy - 1.15*d*z[i]);
    454           DrawLine (sx,          sy - 1.15*d*z[i], sx - d*z[i], sy + 0.58*d*z[i]);
     468        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     469        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     470        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     471            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     472        {
     473          D = d*z[i];
     474          DrawLine (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D);
     475          DrawLine (sx + D, sy + 0.58*D, sx,     sy - 1.15*D);
     476          DrawLine (sx,     sy - 1.15*D, sx - D, sy + 0.58*D);
    455477        }
    456478      }
     
    459481      for (i = 0; i < object[0].Npts; i++) {
    460482        if (!(finite(x[i]) && finite(y[i]))) continue;
    461         sx = x[i]*mxi + y[i]*mxj + bx;
    462         sy = x[i]*myi + y[i]*myj + by;
    463         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    464             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    465         {
    466           DrawLine (sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
    467           DrawLine (sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
    468           DrawLine (sx, sy, sx,          sy - 1.15*d*z[i]);
     483        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     484        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     485        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     486            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     487        {
     488          D = d*z[i];
     489          DrawLine (sx, sy, sx - D, sy - 0.58*D);
     490          DrawLine (sx, sy, sx + D, sy - 0.58*D);
     491          DrawLine (sx, sy, sx,     sy + 1.15*D);
    469492        }
    470493      }
     
    473496      for (i = 0; i < object[0].Npts; i++) {
    474497        if (!(finite(x[i]) && finite(y[i]))) continue;
    475         sx = x[i]*mxi + y[i]*mxj + bx;
    476         sy = x[i]*myi + y[i]*myj + by;
    477         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    478             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    479         {
    480           DrawCircle (sx, sy, d*z[i]);
     498        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     499        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     500        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     501            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     502        {
     503          D = d*z[i];
     504          DrawCircle (sx, sy, D);
    481505        }
    482506      }
     
    485509      for (i = 0; i < object[0].Npts; i++) {
    486510        if (!(finite(x[i]) && finite(y[i]))) continue;
    487         sx = x[i]*mxi + y[i]*mxj + bx;
    488         sy = x[i]*myi + y[i]*myj + by;
    489         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    490             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    491         {
    492           DrawLine (sx + 0.00*d*z[i], sy - 1.00*d*z[i], sx + 0.95*d*z[i], sy - 0.31*d*z[i]);
    493           DrawLine (sx + 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.58*d*z[i], sy + 0.81*d*z[i]);
    494           DrawLine (sx + 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.58*d*z[i], sy + 0.81*d*z[i]);
    495           DrawLine (sx - 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.95*d*z[i], sy - 0.31*d*z[i]);
    496           DrawLine (sx - 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.00*d*z[i], sy - 1.00*d*z[i]);
     511        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     512        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     513        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     514            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     515        {
     516          D = d*z[i];
     517          DrawLine (sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
     518          DrawLine (sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
     519          DrawLine (sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
     520          DrawLine (sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
     521          DrawLine (sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
    497522        }
    498523      }
     
    501526      for (i = 0; i < object[0].Npts; i++) {
    502527        if (!(finite(x[i]) && finite(y[i]))) continue;
    503         sx = x[i]*mxi + y[i]*mxj + bx;
    504         sy = x[i]*myi + y[i]*myj + by;
    505         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    506             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    507         {
    508           DrawLine (sx -      d*z[i], sy,               sx - 0.50*d*z[i], sy + 0.87*d*z[i]);
    509           DrawLine (sx - 0.50*d*z[i], sy + 0.87*d*z[i], sx + 0.50*d*z[i], sy + 0.87*d*z[i]);
    510           DrawLine (sx + 0.50*d*z[i], sy + 0.87*d*z[i], sx +      d*z[i], sy);
    511 
    512           DrawLine (sx +      d*z[i], sy,               sx + 0.50*d*z[i], sy - 0.87*d*z[i]);
    513           DrawLine (sx + 0.50*d*z[i], sy - 0.87*d*z[i], sx - 0.50*d*z[i], sy - 0.87*d*z[i]);
    514           DrawLine (sx - 0.50*d*z[i], sy - 0.87*d*z[i], sx -      d*z[i], sy);
     528        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     529        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     530        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     531            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     532        {
     533          D = d*z[i];
     534          DrawLine (sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
     535          DrawLine (sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
     536          DrawLine (sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
     537
     538          DrawLine (sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
     539          DrawLine (sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
     540          DrawLine (sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
    515541        }
    516542      }
     
    525551      for (i = 0; i + 1 < object[0].Npts; i+=2) {
    526552        if (!(finite(x[i]) && finite(y[i]))) continue;
    527         sx1 = x[i]*mxi + y[i]*mxj + bx;
    528         sy1 = x[i]*myi + y[i]*myj + by;
     553        sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     554        sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    529555        if (!(finite(x[i+1]) && finite(y[i+1]))) continue;
    530         sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    531         sy2 = x[i+1]*myi + y[i+1]*myj + by;
     556        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx + XCENTER;
     557        sy2 = x[i+1]*myi + y[i+1]*myj + by + YCENTER;
    532558        ClipLine (sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
    533559      }
     
    535561  }
    536562  /**** points are not scaled by object.z ***/
     563  /** some rules on how the points are drawn:
     564      1) the smallest point is always a dot (single pixel)
     565      2) the point shape should be invarient on position
     566      3) center of point is always center of a pixel
     567   **/
    537568  else {
    538     d = object[0].size * 0.5 * (graphic->dx + graphic->dy) * 0.003;
     569    d = (int)(object[0].size * hypot((float)graphic->dx, (float)graphic->dy) * 0.003);
    539570    x = object[0].x; y = object[0].y;
    540     if (object[0].ptype == 0) { /* filled box */
    541       for (i = 0; i < object[0].Npts; i++) {
    542         if (!(finite(x[i]) && finite(y[i]))) continue;
    543         sx = x[i]*mxi + y[i]*mxj + bx;
    544         sy = x[i]*myi + y[i]*myj + by;
    545         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    546             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    547         {
    548           FillRectangle (sx - d, sy - d, 2*d, 2*d);
    549         }
    550       }
    551     }
    552     if (object[0].ptype == 1) {         /* open box */
    553       for (i = 0; i < object[0].Npts; i++) {
    554         if (!(finite(x[i]) && finite(y[i]))) continue;
    555         sx = x[i]*mxi + y[i]*mxj + bx;
    556         sy = x[i]*myi + y[i]*myj + by;
     571
     572    if (object[0].ptype == 0) { /* filled box : OK */
     573      for (i = 0; i < object[0].Npts; i++) {
     574        if (!(finite(x[i]) && finite(y[i]))) continue;
     575        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     576        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     577        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     578            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     579        {
     580          FillRectangle (sx - d, sy - d, 2*d + 1, 2*d + 1);
     581        }
     582      }
     583    }
     584    if (object[0].ptype == 1) { /* open box : OK*/
     585      for (i = 0; i < object[0].Npts; i++) {
     586        if (!(finite(x[i]) && finite(y[i]))) continue;
     587        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     588        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    557589        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    558590            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    562594      }
    563595    }
    564     if (object[0].ptype == 2) { /* cross */
    565       for (i = 0; i < object[0].Npts; i++) {
    566         if (!(finite(x[i]) && finite(y[i]))) continue;
    567         sx = x[i]*mxi + y[i]*mxj + bx;
    568         sy = x[i]*myi + y[i]*myj + by;
    569         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    570             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    571         {
    572           DrawLine (sx - d, sy, sx + d + 1, sy);
     596    if (object[0].ptype == 2) { /* cross : OK*/
     597      for (i = 0; i < object[0].Npts; i++) {
     598        if (!(finite(x[i]) && finite(y[i]))) continue;
     599        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     600        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     601        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     602            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     603        {
     604          DrawLine (sx - d, sy, sx + d + 1, sy); // DrawLine does NOT draw the end pixel
    573605          DrawLine (sx, sy - d, sx, sy + d + 1);
    574606        }
    575607      }
    576608    }
    577     if (object[0].ptype == 3) {         /* x */
    578       for (i = 0; i < object[0].Npts; i++) {
    579         if (!(finite(x[i]) && finite(y[i]))) continue;
    580         sx = x[i]*mxi + y[i]*mxj + bx;
    581         sy = x[i]*myi + y[i]*myj + by;
     609    if (object[0].ptype == 3) { /* x : OK */
     610      for (i = 0; i < object[0].Npts; i++) {
     611        if (!(finite(x[i]) && finite(y[i]))) continue;
     612        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     613        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    582614        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    583615            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    584616        {
    585617          /* XDrawLine is a little funny, this is needed to fix endpost errors */
    586           DrawLine (sx + d + 1, sy - d - 1, sx - d, sy + d);
     618          DrawLine (sx - d, sy + d, sx + d + 1, sy - d - 1);
    587619          DrawLine (sx - d, sy - d, sx + d + 1, sy + d + 1);
    588620        }
     
    593625      for (i = 0; i < object[0].Npts; i++) {
    594626        if (!(finite(x[i]) && finite(y[i]))) continue;
    595         sx = x[i]*mxi + y[i]*mxj + bx;
    596         sy = x[i]*myi + y[i]*myj + by;
     627        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     628        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    597629        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    598630            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    609641      for (i = 0; i < object[0].Npts; i++) {
    610642        if (!(finite(x[i]) && finite(y[i]))) continue;
    611         sx = x[i]*mxi + y[i]*mxj + bx;
    612         sy = x[i]*myi + y[i]*myj + by;
     643        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     644        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    613645        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    614646            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    623655      for (i = 0; i < object[0].Npts; i++) {
    624656        if (!(finite(x[i]) && finite(y[i]))) continue;
    625         sx = x[i]*mxi + y[i]*mxj + bx;
    626         sy = x[i]*myi + y[i]*myj + by;
    627         if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    628             (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    629         {
    630           DrawLine (sx, sy, sx - d, sy + 0.58*d);
    631           DrawLine (sx, sy, sx + d, sy + 0.58*d);
    632           DrawLine (sx, sy, sx,     sy - 1.15*d);
     657        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     658        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     659        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     660            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     661        {
     662          DrawLine (sx, sy, sx - d, sy - 0.58*d);
     663          DrawLine (sx, sy, sx + d, sy - 0.58*d);
     664          DrawLine (sx, sy, sx,     sy + 1.15*d);
    633665        }
    634666      }
     
    637669      for (i = 0; i < object[0].Npts; i++) {
    638670        if (!(finite(x[i]) && finite(y[i]))) continue;
    639         sx = x[i]*mxi + y[i]*mxj + bx;
    640         sy = x[i]*myi + y[i]*myj + by;
     671        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     672        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    641673        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    642674            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    649681      for (i = 0; i < object[0].Npts; i++) {
    650682        if (!(finite(x[i]) && finite(y[i]))) continue;
    651         sx = x[i]*mxi + y[i]*mxj + bx;
    652         sy = x[i]*myi + y[i]*myj + by;
     683        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     684        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    653685        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    654686            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    665697      for (i = 0; i < object[0].Npts; i++) {
    666698        if (!(finite(x[i]) && finite(y[i]))) continue;
    667         sx = x[i]*mxi + y[i]*mxj + bx;
    668         sy = x[i]*myi + y[i]*myj + by;
     699        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     700        sy = x[i]*myi + y[i]*myj + by + YCENTER;
    669701        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    670702            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
     
    687719      for (i = 0; i + 1 < object[0].Npts; i+=2) {
    688720        if (!(finite(x[i]) && finite(y[i]))) continue;
    689         sx1 = x[i]*mxi + y[i]*mxj + bx;
    690         sy1 = x[i]*myi + y[i]*myj + by;
    691         sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    692         sy2 = x[i+1]*myi + y[i+1]*myj + by;
     721        sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     722        sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
     723        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx + XCENTER;
     724        sy2 = x[i+1]*myi + y[i+1]*myj + by + YCENTER;
    693725        ClipLine (sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
    694726      }
     
    723755  for (i = 0; i < object[0].Npts; i++) {
    724756    if (!(finite(x[i]) && finite(y[i]) && finite(dxp[i]))) continue;
    725     sx0 = x[i]*mxi + y[i]*mxj + bx;
    726     sy0 = x[i]*myi + y[i]*myj + by;
    727     sx1 = (x[i] + dxp[i])*mxi + y[i]*mxj + bx;
    728     sy1 = (x[i] + dxp[i])*myi + y[i]*myj + by;
     757    sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     758    sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
     759    sx1 = (x[i] + dxp[i])*mxi + y[i]*mxj + bx + XCENTER;
     760    sy1 = (x[i] + dxp[i])*myi + y[i]*myj + by + YCENTER;
    729761    if (((sx0 > graph[0].axis[0].fx) && (sx0 < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    730762         (sy0 < graph[0].axis[1].fy) && (sy0 > graph[0].axis[1].fy + graph[0].axis[1].dfy)) ||
     
    740772    }
    741773    if (!(finite(x[i]) && finite(y[i]) && finite(dxm[i]))) continue;
    742     sx0 = x[i]*mxi + y[i]*mxj + bx;
    743     sy0 = x[i]*myi + y[i]*myj + by;
    744     sx1 = (x[i] - dxm[i])*mxi + y[i]*mxj + bx;
    745     sy1 = (x[i] - dxm[i])*myi + y[i]*myj + by;
     774    sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     775    sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
     776    sx1 = (x[i] - dxm[i])*mxi + y[i]*mxj + bx + XCENTER;
     777    sy1 = (x[i] - dxm[i])*myi + y[i]*myj + by + YCENTER;
    746778    if (((sx0 > graph[0].axis[0].fx) && (sx0 < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    747779         (sy0 < graph[0].axis[1].fy) && (sy0 > graph[0].axis[1].fy + graph[0].axis[1].dfy)) ||
     
    785817  for (i = 0; i < object[0].Npts; i++) {
    786818    if (!(finite(x[i]) && finite(y[i]) && finite(dyp[i]))) continue;
    787     sx0 = x[i]*mxi + y[i]*mxj + bx;
    788     sy0 = x[i]*myi + y[i]*myj + by;
     819    sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     820    sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
    789821    sx1 = sx0 + dyp[i]*mxj;
    790822    sy1 = sy0 + dyp[i]*myj;
     
    802834    }
    803835    if (!(finite(x[i]) && finite(y[i]) && finite(dym[i]))) continue;
    804     sx0 = x[i]*mxi + y[i]*mxj + bx;
    805     sy0 = x[i]*myi + y[i]*myj + by;
    806     sx1 = x[i]*mxi + (y[i] - dym[i])*mxj + bx;
    807     sy1 = x[i]*myi + (y[i] - dym[i])*myj + by;
     836    sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     837    sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
     838    sx1 = x[i]*mxi + (y[i] - dym[i])*mxj + bx + XCENTER;
     839    sy1 = x[i]*myi + (y[i] - dym[i])*myj + by + YCENTER;
    808840    if (((sx0 > graph[0].axis[0].fx) && (sx0 < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    809841         (sy0 < graph[0].axis[1].fy) && (sy0 > graph[0].axis[1].fy + graph[0].axis[1].dfy)) ||
  • branches/czw_branch/20110406/Ohana/src/kapa2/src/PSObjects.c

    r31160 r31606  
    365365            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    366366          {
    367             DrawLine (sx - d*z[i], sy + 0.58*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
    368             DrawLine (sx + d*z[i], sy + 0.58*d*z[i], sx,          sy - 1.15*d*z[i]);
    369             DrawLine (sx,          sy - 1.15*d*z[i], sx - d*z[i], sy + 0.58*d*z[i]);
     367            DrawLine (sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i]);
     368            DrawLine (sx + d*z[i], sy - 0.58*d*z[i], sx,          sy + 1.15*d*z[i]);
     369            DrawLine (sx,          sy + 1.15*d*z[i], sx - d*z[i], sy - 0.58*d*z[i]);
    370370          }
    371371      }
     
    538538            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    539539          {
    540             DrawLine (sx, sy, sx - d, sy - 0.58*d);
    541             DrawLine (sx, sy, sx + d, sy - 0.58*d);
    542             DrawLine (sx, sy, sx,     sy + 1.15*d);
     540            DrawLine (sx, sy, sx - d, sy + 0.58*d);
     541            DrawLine (sx, sy, sx + d, sy + 0.58*d);
     542            DrawLine (sx, sy, sx,     sy - 1.15*d);
    543543          }
    544544      }
  • branches/czw_branch/20110406/Ohana/src/kapa2/src/bDrawObjects.c

    r31160 r31606  
    44# define DrawCircle(BUF,X1,Y1,R) (bDrawCircle (BUF, (X1), (Y1), (R)))
    55# 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)))
    6 # define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
    7 # define FillTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriFill (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
     6# 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)))
     7# define FillTriangle(BUF,X1,Y1,dX,dY) (bDrawTriFill (BUF, (X1), (Y1), (dX), (dY)))
    88# define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
    99
     
    260260  float *x, *y, *z;
    261261  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
    262   double sx, sy, d, sx1, sy1, sx2, sy2;
     262  int sx, sy, sx1, sy1, sx2, sy2, d, D;
    263263
    264264  mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);
     
    288288            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    289289        {
    290           FillRectangle (buffer, sx, sy, 2*d*z[i], 2*d*z[i]);
     290          D = d*z[i];
     291          FillRectangle (buffer, sx, sy, 2*D, 2*D);
    291292        }
    292293      }
     
    300301            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    301302        {
    302           DrawRectangle (buffer, sx, sy, 2*d*z[i], 2*d*z[i]);
     303          D = d*z[i];
     304          DrawRectangle (buffer, sx, sy, 2*D, 2*D);
    303305        }
    304306      }
     
    312314            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    313315        {
    314           DrawLine (buffer, sx - d*z[i], sy, sx + d*z[i], sy);
    315           DrawLine (buffer, sx, sy - d*z[i], sx, sy + d*z[i]);
     316          D = d*z[i];
     317          DrawLine (buffer, sx - D, sy, sx + D, sy);
     318          DrawLine (buffer, sx, sy - D, sx, sy + D);
    316319        }
    317320      }
     
    325328            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    326329        {
    327           DrawLine (buffer, sx + d*z[i], sy - d*z[i], sx - d*z[i], sy + d*z[i]);
    328           DrawLine (buffer, sx - d*z[i], sy - d*z[i], sx + d*z[i], sy + d*z[i]);
     330          D = d*z[i];
     331          DrawLine (buffer, sx + D, sy - D, sx - D, sy + D);
     332          DrawLine (buffer, sx - D, sy - D, sx + D, sy + D);
    329333        }
    330334      }
     
    338342            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    339343        {
    340           FillTriangle (buffer, sx - d*z[i], sy - 0.58*d*z[i], sx + d*z[i], sy - 0.58*d*z[i], sx, sy + 1.15*d*z[i]);
     344          D = d*z[i];
     345          // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     346          FillTriangle (buffer, sx, sy + 0.58*D, D, -1.73*D);
    341347        }
    342348      }
     
    350356            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    351357        {
    352           OpenTriangle (buffer, sx - d*z[i], sy + 0.58*d*z[i], sx, sy - 1.15*d*z[i], sx + d*z[i], sy + 0.58*d*z[i]);
     358          D = d*z[i];
     359          OpenTriangle (buffer, sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
    353360        }
    354361      }
     
    362369            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    363370        {
    364           DrawLine (buffer, sx, sy, sx - d*z[i], sy + 0.58*d*z[i]);
    365           DrawLine (buffer, sx, sy, sx + d*z[i], sy + 0.58*d*z[i]);
    366           DrawLine (buffer, sx, sy, sx,          sy - 1.15*d*z[i]);
     371          D = d*z[i];
     372          DrawLine (buffer, sx, sy, sx - D, sy - 0.58*D);
     373          DrawLine (buffer, sx, sy, sx + D, sy - 0.58*D);
     374          DrawLine (buffer, sx, sy, sx,     sy + 1.15*D);
    367375        }
    368376      }
     
    376384            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    377385        {
    378           DrawCircle (buffer, sx, sy, d*z[i]);
     386          D = d*z[i];
     387          DrawCircle (buffer, sx, sy, D);
    379388        }
    380389      }
     
    388397            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    389398        {
    390           DrawLine (buffer, sx + 0.00*d*z[i], sy - 1.00*d*z[i], sx + 0.95*d*z[i], sy - 0.31*d*z[i]);
    391           DrawLine (buffer, sx + 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.58*d*z[i], sy + 0.81*d*z[i]);
    392           DrawLine (buffer, sx + 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.58*d*z[i], sy + 0.81*d*z[i]);
    393           DrawLine (buffer, sx - 0.58*d*z[i], sy + 0.81*d*z[i], sx - 0.95*d*z[i], sy - 0.31*d*z[i]);
    394           DrawLine (buffer, sx - 0.95*d*z[i], sy - 0.31*d*z[i], sx + 0.00*d*z[i], sy - 1.00*d*z[i]);
     399          D = d*z[i];
     400          DrawLine (buffer, sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
     401          DrawLine (buffer, sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
     402          DrawLine (buffer, sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
     403          DrawLine (buffer, sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
     404          DrawLine (buffer, sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
    395405        }
    396406      }
     
    404414            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    405415        {
    406           DrawLine (buffer, sx -      d*z[i], sy,               sx - 0.50*d*z[i], sy + 0.87*d*z[i]);
    407           DrawLine (buffer, sx - 0.50*d*z[i], sy + 0.87*d*z[i], sx + 0.50*d*z[i], sy + 0.87*d*z[i]);
    408           DrawLine (buffer, sx + 0.50*d*z[i], sy + 0.87*d*z[i], sx +      d*z[i], sy);
    409 
    410           DrawLine (buffer, sx +      d*z[i], sy,               sx + 0.50*d*z[i], sy - 0.87*d*z[i]);
    411           DrawLine (buffer, sx + 0.50*d*z[i], sy - 0.87*d*z[i], sx - 0.50*d*z[i], sy - 0.87*d*z[i]);
    412           DrawLine (buffer, sx - 0.50*d*z[i], sy - 0.87*d*z[i], sx -      d*z[i], sy);
     416          D = d*z[i];
     417          DrawLine (buffer, sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
     418          DrawLine (buffer, sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
     419          DrawLine (buffer, sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
     420          DrawLine (buffer, sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
     421          DrawLine (buffer, sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
     422          DrawLine (buffer, sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
    413423        }
    414424      }
     
    431441    }
    432442  } else {
    433     d = object[0].size * 0.5 * (graphic->dx + graphic->dy) * 0.003;
     443    d = (int)(object[0].size * hypot((float)graphic->dx, (float)graphic->dy) * 0.003);
    434444    x = object[0].x; y = object[0].y;
     445
    435446    if (object[0].ptype == 0) { /* filled box */
    436447      for (i = 0; i < object[0].Npts; i++) {
     
    457468      }
    458469    }
    459     if (object[0].ptype == 2) { /* cross */
     470    if (object[0].ptype == 2) { /* cross : OK */
    460471      for (i = 0; i < object[0].Npts; i++) {
    461472        if (!(finite(x[i]) && finite(y[i]))) continue;
     
    491502            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    492503        {
    493           FillTriangle (buffer, sx - d, sy - 0.58*d, sx + d, sy - 0.58*d, sx, sy + 1.15*d);
     504          FillTriangle (buffer, sx, sy + 0.58*d, d, -1.73*d);
    494505        }
    495506      }
  • branches/czw_branch/20110406/Ohana/src/libdvo/Makefile

    r31160 r31606  
    101101
    102102$(AINC)/autocode.h: $(AINCS) $(ADEF)/autocode.h $(ADEF)/common.h
    103         @echo "make $@ from $^"
    104         cd $(AUTO) && make $@
     103        @echo "$(MAKE) $@ from $^"
     104        cd $(AUTO) && $(MAKE) $@
    105105
    106106# generic rule for AINCS
    107107$(AINC)/%.h : $(ADEF)/%.d $(ADEF)/autocode.h $(ADEF)/common.h
    108         @echo "make $@ from $^"
    109         cd $(AUTO) && make $@
     108        @echo "$(MAKE) $@ from $^"
     109        cd $(AUTO) && $(MAKE) $@
    110110
    111111# generic rule for ASRC
    112112$(ASRC)/%.c : $(ADEF)/%.d $(ADEF)/autocode.c $(AINC)/%.h
    113         @echo "make $@ from $^"
    114         cd $(AUTO) && make $@
     113        @echo "$(MAKE) $@ from $^"
     114        cd $(AUTO) && $(MAKE) $@
    115115
    116116# generic rule for AOBJS
    117117$(ASRC)/%.$(ARCH).o : $(ASRC)/%.c
    118         @echo "make $@ from $^"
    119         cd $(AUTO) && make $@
     118        @echo "$(MAKE) $@ from $^"
     119        cd $(AUTO) && $(MAKE) $@
    120120
    121121tabletest: install
     
    124124clean: cleandef
    125125cleandef:
    126         cd $(AUTO) && make clean
     126        cd $(AUTO) && $(MAKE) clean
    127127
    128128.PRECIOUS: $(ASRC)/%.c
  • branches/czw_branch/20110406/Ohana/src/libdvo/include/dvo.h

    r31160 r31606  
    2020  DVO_FORMAT_PS1_DEV_2,
    2121  DVO_FORMAT_PS1_DEV_3,
     22  DVO_FORMAT_PS1_REF,
    2223  DVO_FORMAT_PS1_V1,
    2324  DVO_FORMAT_PS1_V2,
    24   DVO_FORMAT_PS1_REF
    2525} DVOTableFormat;
    2626
     
    210210} PhotCodeData;
    211211
     212// a reduced-subset structure for relphot
     213typedef struct {
     214  double         R;
     215  double         D;
     216  unsigned short Nmeasure;
     217  int            measureOffset;
     218  uint32_t       flags;
     219} AverageTiny;
     220
     221// a reduced-subset structure for relphot
     222typedef struct {
     223  float          dR;
     224  float          dD;
     225  float          M;
     226  float          Mcal;
     227  float          dM;
     228  float          airmass;
     229  float          Xccd;
     230  float          Yccd;
     231  float          dt;
     232  int            t;
     233  unsigned int   averef;
     234  unsigned int   imageID;
     235  unsigned int   dbFlags;
     236  unsigned short photcode;
     237} MeasureTiny;
     238
    212239/* a catalog contains this data */
    213240typedef struct Catalog {
     
    226253  off_t Naves_disk, Nmeas_disk, Nmiss_disk, Nsecf_disk; /* current number of each component on disk */
    227254  off_t Naves_off,  Nmeas_off,  Nmiss_off,  Nsecf_off;  /* index of first loaded data value */
     255
     256  // note that we use these for the full-sky relphot analysis
     257  AverageTiny *averageT;
     258  MeasureTiny *measureT;
    228259
    229260  /* the Nsecf_* values above are number of table rows (eg, Naverage*Nsecfilt) */
     
    330361int PhotColor (Average *average, SecFilt *secfilt, Measure *measure, int c1, int c2, double *color);
    331362
     363float PhotInstTiny (MeasureTiny *measure);
     364float PhotCatTiny (MeasureTiny *measure);
     365float PhotAperTiny (MeasureTiny *measure);
     366float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
     367float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt);
     368float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code);
     369float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
     370float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure);
     371float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
     372float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt);
     373
     374float PhotColorForCodeTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code);
     375int PhotColorTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, int c1, int c2, double *color);
     376
     377
    332378PhotCodeData *GetPhotcodeTable (void);
    333379void SetPhotcodeTable (PhotCodeData *);
  • branches/czw_branch/20110406/Ohana/src/libdvo/src/dvo_catalog_split.c

    r29938 r31606  
    448448    catalog[0].measure = FtableToMeasure (&ftable, &Nmeasure, &catalog[0].catformat);
    449449    if (Nmeasure != Nrows) {
    450       fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  Nrows);
     450      // XXX this condition denotes the eof has been reached; not an error or a warning
     451      // fprintf (stderr, "Warning: mismatch between Nmeasure in PHU and Table headers ("OFF_T_FMT" vs "OFF_T_FMT")\n",  Nmeasure,  Nrows);
    451452    }
    452453    gfits_free_header (&header);
  • branches/czw_branch/20110406/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r29938 r31606  
    536536  return (TRUE);
    537537}
     538
     539/******** alternate photometry conversion functions using MeasureTiny and AverageTiny *********/
     540float PhotInstTiny (MeasureTiny *measure) {
     541
     542  int Np;
     543  float M;
     544
     545  Np = photcodes[0].hashcode[measure[0].photcode];
     546  if (Np == -1) return (NAN);
     547
     548  if (photcodes[0].code[Np].type == PHOT_REF) {
     549    M = measure[0].M;
     550    return (M);
     551  }
     552
     553  M = measure[0].M - measure[0].dt - ZERO_POINT;
     554         
     555  return (M);
     556
     557}
     558
     559float PhotCatTiny (MeasureTiny *measure) {
     560
     561  int Np;
     562  float Mcat;
     563  PhotCode *code;
     564
     565  Np = photcodes[0].hashcode[measure[0].photcode];
     566  if (Np == -1) return (NAN);
     567
     568  if (photcodes[0].code[Np].type == PHOT_REF) {
     569    Mcat = measure[0].M;
     570    return (Mcat);
     571  }
     572  code = &photcodes[0].code[Np];
     573  Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     574 
     575  return (Mcat);
     576}
     577
     578# if (0)
     579float PhotAperTiny (MeasureTiny *measure) {
     580
     581  int Np;
     582  float Mcat;
     583  PhotCode *code;
     584
     585  Np = photcodes[0].hashcode[measure[0].photcode];
     586  if (Np == -1) return (NAN);
     587
     588  if (photcodes[0].code[Np].type == PHOT_REF) {
     589    Mcat = measure[0].Map;
     590    return (Mcat);
     591  }
     592  code = &photcodes[0].code[Np];
     593  Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     594 
     595  return (Mcat);
     596}
     597# endif
     598
     599float PhotSysTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
     600
     601  int i, Np;
     602  float Mcat, Mcol, Msys, mc, Mc;
     603  PhotCode *code;
     604
     605  Np = photcodes[0].hashcode[measure[0].photcode];
     606  if (Np == -1) return (NAN);
     607
     608  if (photcodes[0].code[Np].type == PHOT_REF) {
     609    Msys = measure[0].M;
     610    return (Msys);
     611  }
     612  code = &photcodes[0].code[Np];
     613  Mcat = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     614
     615  /* for DEP, color must be made of PRI/SEC */
     616  mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     617  if (isnan(mc)) return (Mcat);
     618  mc = mc - SCALE*code[0].dX;
     619
     620  Mc = mc;
     621  Mcol = 0;
     622  for (i = 0; i < code[0].Nc; i++) {
     623    Mcol += code[0].X[i]*Mc;
     624    Mc *= mc;
     625  }
     626  Msys = Mcat + Mcol;
     627  return (Msys);
     628}
     629
     630float PhotRelTiny (MeasureTiny *measure, AverageTiny *average, SecFilt *secfilt) {
     631
     632  int i, Np;
     633  float Mcat, Mcol, Mrel, mc, Mc;
     634  PhotCode *code;
     635
     636  Np = photcodes[0].hashcode[measure[0].photcode];
     637  if (Np == -1) return (NAN);
     638
     639  if (photcodes[0].code[Np].type == PHOT_REF) {
     640    Mcat = measure[0].M;
     641    return (Mcat);
     642  }
     643  code = &photcodes[0].code[Np];
     644  Mrel = measure[0].M - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     645
     646  /* for DEP, color must be made of PRI/SEC */
     647  mc = PhotColorForCodeTiny (average, secfilt, NULL, code);
     648  if (isnan(mc)) return (Mrel);
     649  mc = mc - SCALE*code[0].dX;
     650
     651  Mc = mc;
     652  Mcol = 0;
     653  for (i = 0; i < code[0].Nc; i++) {
     654    Mcol += code[0].X[i]*Mc;
     655    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     656  }
     657  Mrel += Mcol;
     658  return (Mrel);
     659}
     660
     661/* return calibrated magnitude from measure for given photcode */
     662float PhotCalTiny (MeasureTiny *thisone, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) {
     663
     664  int i, Np;
     665  float Mcal, Mrel, Mcol, mc, Mc;
     666
     667  if (code == NULL) return NAN;
     668
     669  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     670  Np = photcodes[0].hashcode[thisone[0].photcode];
     671  if (Np == -1) return (NAN);
     672
     673  if (photcodes[0].code[Np].type == PHOT_REF) {
     674    Mrel = thisone[0].M;
     675    return (Mrel);
     676  }
     677  if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
     678
     679  Mcal = PhotRelTiny (thisone, average, secfilt) + SCALE*code[0].C;
     680
     681  mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     682  if (isnan(mc)) return (Mcal);
     683  mc = mc - SCALE*code[0].dX;
     684
     685  Mc = mc;
     686  Mcol = 0;
     687  for (i = 0; i < code[0].Nc; i++) {
     688    Mcol += code[0].X[i]*Mc;
     689    Mc *= mc;
     690  }
     691  Mcal += Mcol;
     692  return (Mcal);
     693}
     694
     695/* color term may not use DEP magnitude */
     696float PhotColorForCodeTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, PhotCode *code) {
     697
     698  int i, Ns1, Ns2, Ns;
     699  float m1, m2, mc;
     700  PhotCode *color;
     701
     702  m1 = m2 = NAN;
     703
     704  if (measure == NULL) {
     705    Ns1 = photcodes[0].hashNsec[code[0].c1];
     706    Ns2 = photcodes[0].hashNsec[code[0].c2];
     707 
     708    m1 = (Ns1 == -1) ? NAN : secfilt[Ns1].M;
     709    m2 = (Ns2 == -1) ? NAN : secfilt[Ns2].M;
     710    mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
     711    return (mc);
     712  }
     713
     714  /* find magnitude matching first color term */
     715  color = GetPhotcodebyCode (code[0].c1);
     716  if (color == NULL) return (NAN);
     717  if (color[0].type == PHOT_REF) {
     718    for (i = 0; (i < average[0].Nmeasure) && (isnan(m1)); i++) {
     719      if (measure[i].photcode == color[0].code) {
     720        m1 = measure[i].M;
     721      }
     722    }
     723  } else {
     724    Ns = photcodes[0].hashNsec[color[0].code];
     725    m1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     726  }     
     727
     728  /* find magnitude matching second color term */
     729  color = GetPhotcodebyCode (code[0].c2);
     730  if (color == NULL) return (NAN);
     731  if (color[0].type == PHOT_REF) {
     732    for (i = 0; (i < average[0].Nmeasure) && (isnan(m2)); i++) {
     733      if (measure[i].photcode == color[0].code) {
     734        m2 = measure[i].M;
     735      }
     736    }
     737  } else {
     738    Ns = photcodes[0].hashNsec[color[0].code];
     739    m2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     740  }     
     741  mc = (isnan(m1) || isnan(m2)) ? NAN : (m1 - m2);
     742  return (mc);
     743}
     744
     745/* return calibrated magnitude from average/secfilt for given photcode */
     746float PhotRefTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure) {
     747
     748  int i, Ns;
     749  float Mave, Mref, Mcol, mc;
     750  double Mc;
     751
     752  if (code == NULL) return NAN;
     753
     754  Ns = photcodes[0].hashNsec[code[0].code];
     755  Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
     756  Mref = Mave + SCALE*code[0].C;
     757
     758  mc = PhotColorForCodeTiny (average, secfilt, measure, code);
     759  if (isnan(mc)) return (Mref);
     760  mc = mc - SCALE*code[0].dX;
     761
     762  Mc = mc;
     763  Mcol = 0;
     764  for (i = 0; i < code[0].Nc; i++) {
     765    Mcol += code[0].X[i]*Mc;
     766    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     767  }
     768  Mref += Mcol;
     769  return (Mref);
     770}
     771
     772/***/
     773float PhotAveTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
     774
     775  int Ns;
     776  float Mave;
     777
     778  if (code == NULL) return NAN;
     779
     780  Ns = photcodes[0].hashNsec[code[0].code];
     781  Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
     782  return (Mave);
     783}
     784
     785float PhotdMTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
     786
     787  int Ns;
     788  float dM;
     789
     790  if (code == NULL) return NAN;
     791
     792  Ns = photcodes[0].hashNsec[code[0].code];
     793  dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
     794  return (dM);
     795}
     796
     797// XXX return NAN or NAN_S_SHORT? (secfilt->Xm is short)
     798float PhotXmTiny (PhotCode *code, AverageTiny *average, SecFilt *secfilt) {
     799
     800  int Ns;
     801  short Mi;
     802  float Xm;
     803
     804  if (code == NULL) return NAN;
     805
     806  Ns = photcodes[0].hashNsec[code[0].code];
     807  Mi = (Ns == -1) ? NAN : secfilt[Ns].Xm;
     808  Xm = (isnan(Mi)) ? -1.0 : pow (10.0, 0.01*Mi);
     809  return (Xm);
     810}
     811
     812/* given a photcode pair c1 & c2, return the color of this star (NaN if not found) */
     813int PhotColorTiny (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, int c1, int c2, double *color) {
     814
     815  int i, Ns;
     816  double M1, M2, dM;
     817  PhotCode *code;
     818 
     819  code = GetPhotcodebyCode (c1);
     820  if (code == NULL) return (FALSE);
     821  if (code[0].type == PHOT_REF) {
     822    for (i = 0; i < average[0].Nmeasure; i++) {
     823      if (measure[i].photcode == c1) {
     824        M1 = measure[i].M;
     825        goto filter1;
     826      }
     827    }   
     828    return (FALSE);
     829  } else {
     830    Ns = photcodes[0].hashNsec[code[0].code];
     831    M1 = (Ns == -1) ? NAN : secfilt[Ns].M;
     832  }     
     833
     834filter1:
     835  code = GetPhotcodebyCode (c2);
     836  if (code == NULL) return (FALSE);
     837  if (code[0].type == PHOT_REF) {
     838    for (i = 0; i < average[0].Nmeasure; i++) {
     839      if (measure[i].photcode == c2) {
     840        M2 = measure[i].M;
     841        goto filter2;
     842      }
     843    }   
     844    return (FALSE);
     845  } else {
     846    Ns = photcodes[0].hashNsec[code[0].code];
     847    M2 = (Ns == -1) ? NAN : secfilt[Ns].M;
     848  }     
     849 
     850filter2:
     851
     852  dM = M1 - M2;
     853  *color = dM;
     854 
     855  return (TRUE);
     856}
     857/***********************************************/
    538858
    539859// Create a map between the secfilt values from one photcode table to another
  • branches/czw_branch/20110406/Ohana/src/libkapa/include/kapa.h

    r31160 r31606  
    255255void bDrawRectFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2);
    256256void bDrawTriOpen  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
    257 void bDrawTriFill  (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3);
     257void bDrawTriFill  (bDrawBuffer *buffer, double x1, double y1, double dx, double dy);
    258258
    259259/* bDrawRotFont.c */
  • branches/czw_branch/20110406/Ohana/src/libkapa/src/bDrawFuncs.c

    r29938 r31606  
    134134  Y2 = MIN (MAX (ROUND (y2), 1), buffer[0].Ny - 1);
    135135
    136   bDrawLineHorizontal (buffer, X1, X2, Y1);
    137   bDrawLineHorizontal (buffer, X1, X2, Y2);
     136  bDrawLineHorizontal (buffer, X1, X2 + 1, Y1);
     137  bDrawLineHorizontal (buffer, X1, X2 + 1, Y2);
    138138  bDrawLineVertical   (buffer, X1, Y1, Y2);
    139139  bDrawLineVertical   (buffer, X2, Y1, Y2);
     
    275275}
    276276
    277 void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double x2, double y2, double x3, double y3) {
    278 
    279   bDrawTriOpen (buffer, x1, y1, x2, y2, x3, y3);
     277// upright triangle with base of width 2 dX + 1, height of dY, center of base at x1, y1
     278void bDrawTriFill (bDrawBuffer *buffer, double x1, double y1, double dx, double dy) {
     279
     280  int xs, xe, x, y;
     281  float e, m;
     282
     283  double dX = fabs(dx);
     284 
     285  xs = x1 - dX;
     286  xe = x1 + dX + 1;
     287  e = 0;
     288  m = dX / dy;
     289
     290  if (dy > 0.0) {
     291    for (y = y1; y < y1 + dy + 1; y++) {
     292      for (x = xs; x < xe; x++) {
     293        bDrawPoint (buffer, x, y);
     294      }
     295      e += m;
     296      if (e > 0.5) {
     297        xs ++;
     298        xe --;
     299        e -= 1.0;
     300      }
     301      if (e < -0.5) {
     302        xs ++;
     303        xe --;
     304        e += 1.0;
     305      }
     306    }   
     307  } else {
     308    for (y = y1; y > y1 + dy - 1; y--) {
     309      for (x = xs; x < xe; x++) {
     310        bDrawPoint (buffer, x, y);
     311      }
     312      e += m;
     313      if (e > 0.5) {
     314        xs ++;
     315        xe --;
     316        e -= 1.0;
     317      }
     318      if (e < -0.5) {
     319        xs ++;
     320        xe --;
     321        e += 1.0;
     322      }
     323    }   
     324  }
     325 
    280326  return;
    281327}
  • branches/czw_branch/20110406/Ohana/src/libohana/Makefile

    r28241 r31606  
    5454testcode: install $(TEST)
    5555test:
    56         make testcode
     56        $(MAKE) testcode
    5757        for i in $(TEST); do $$i; done
    5858
  • branches/czw_branch/20110406/Ohana/src/misc/Makefile

    r12842 r31606  
    3737
    3838cfhtlog:
    39         make $(DESTBIN)/cfhtlog
     39        $(MAKE) $(DESTBIN)/cfhtlog
    4040
    4141# copied from Makefile.Common : use a single c file: foo : foo.c
     
    5656
    5757%.install:
    58         make $(DESTBIN)/$*
     58        $(MAKE) $(DESTBIN)/$*
    5959
    6060install:
    61         for i in $(PROGRAMS); do make $$i.install || exit; done
     61        for i in $(PROGRAMS); do $(MAKE) $$i.install || exit; done
    6262
    6363%.clean:
  • branches/czw_branch/20110406/Ohana/src/opihi/Makefile

    r8566 r31606  
    2323
    2424all:
    25         for i in $(PROGRAM) $(SPECIAL); do make $$i || exit; done
    26         make pantasks_client
    27         make pantasks_server
     25        for i in $(PROGRAM) $(SPECIAL); do $(MAKE) $$i || exit; done
     26        $(MAKE) pantasks_client
     27        $(MAKE) pantasks_server
    2828
    2929libs:
    30         for i in $(LIBS); do make $$i || exit; done
     30        for i in $(LIBS); do $(MAKE) $$i || exit; done
    3131
    3232extras:
    33         for i in $(EXTRAS); do make $$i || exit; done
     33        for i in $(EXTRAS); do $(MAKE) $$i || exit; done
    3434
    3535install:
    36         for i in $(PROGRAM) $(SPECIAL); do make $$i.install || exit; done
    37         make pantasks_client.install
    38         make pantasks_server.install
     36        for i in $(PROGRAM) $(SPECIAL); do $(MAKE) $$i.install || exit; done
     37        $(MAKE) pantasks_client.install
     38        $(MAKE) pantasks_server.install
    3939
    4040extras-install:
    41         for i in $(EXTRAS); do make $$i.install || exit; done
     41        for i in $(EXTRAS); do $(MAKE) $$i.install || exit; done
    4242
    4343clean:
    44         for i in $(PROGRAM) $(SPECIAL) $(EXTRAS) $(LIBS); do make $$i.clean || exit; done
     44        for i in $(PROGRAM) $(SPECIAL) $(EXTRAS) $(LIBS); do $(MAKE) $$i.clean || exit; done
    4545
    4646libs-uninstall:
    47         for i in $(LIBS); do make $$i.uninstall || exit; done
     47        for i in $(LIBS); do $(MAKE) $$i.uninstall || exit; done
    4848
    4949dist: clean
    50         for i in $(PROGRAM) $(SPECIAL) $(EXTRAS) $(LIBS); do make $$i.dist || exit; done
     50        for i in $(PROGRAM) $(SPECIAL) $(EXTRAS) $(LIBS); do $(MAKE) $$i.dist || exit; done
    5151        rm -rf bin
    5252        rm -rf lib
     
    5555
    5656pantasks_client pantasks_server:
    57         if [ -d pantasks ]; then (cd pantasks && make $@); fi
     57        if [ -d pantasks ]; then (cd pantasks && $(MAKE) $@); fi
    5858
    5959pantasks_client.install: pantasks_client
    60         if [ -d pantasks ]; then (cd pantasks && make $@); fi
     60        if [ -d pantasks ]; then (cd pantasks && $(MAKE) $@); fi
    6161
    6262pantasks_server.install: pantasks_server
    63         if [ -d pantasks ]; then (cd pantasks && make $@); fi
     63        if [ -d pantasks ]; then (cd pantasks && $(MAKE) $@); fi
    6464
    6565$(PROGRAM) $(LIBS) $(EXTRAS):
    66         if [ -d "$@" ]; then (cd $@ && make); fi
     66        if [ -d "$@" ]; then (cd $@ && $(MAKE)); fi
    6767
    6868%.install:
    69         if [ -d "$*" ]; then make $*; fi
    70         if [ -d "$*" ]; then (cd $* && make install); fi
     69        if [ -d "$*" ]; then $(MAKE) $*; fi
     70        if [ -d "$*" ]; then (cd $* && $(MAKE) install); fi
    7171
    7272%.clean:
    73         if [ -d "$*" ]; then (cd $* && make clean); fi
     73        if [ -d "$*" ]; then (cd $* && $(MAKE) clean); fi
    7474
    7575%.dist:
    76         if [ -d "$*" ]; then (cd $* && make dist); fi
     76        if [ -d "$*" ]; then (cd $* && $(MAKE) dist); fi
    7777
    7878%.uninstall:
    79         if [ -d "$*" ]; then (cd $* && make uninstall); fi
     79        if [ -d "$*" ]; then (cd $* && $(MAKE) uninstall); fi
    8080
    8181.PHONY: $(PROGRAM) $(LIBS) pantasks_server pantasks_client
  • branches/czw_branch/20110406/Ohana/src/opihi/cmd.data/Makefile

    r29938 r31606  
    141141$(SRC)/vpop.$(ARCH).o              \
    142142$(SRC)/vroll.$(ARCH).o             \
     143$(SRC)/vshift.$(ARCH).o            \
    143144$(SRC)/vsmooth.$(ARCH).o           \
    144145$(SRC)/vstats.$(ARCH).o            \
  • branches/czw_branch/20110406/Ohana/src/opihi/cmd.data/gridify.c

    r20936 r31606  
    44
    55  int i, Nx, Ny, Xb, Yb, Normalize, N;
    6   float Xmin, Xmax, dX, Ymin, Ymax, dY;
     6  float Xmin, Xmax, dX, Ymin, Ymax, dY, initValue;
    77  float *buf, *val;
    88  int *Nval;
     
    1515    remove_argument (N, &argc, argv);
    1616    Normalize = FALSE;
     17  }
     18
     19  initValue = 0.0;
     20  if ((N = get_argument (argc, argv, "-init-value"))) {
     21    remove_argument (N, &argc, argv);
     22    initValue = atof(argv[N]);
     23    remove_argument (N, &argc, argv);
    1724  }
    1825
     
    6976  buf = (float *) bf[0].matrix.buffer;
    7077  for (i = 0; i < Nx*Ny; i++) {
     78    buf[i] = initValue;
    7179    if (Normalize) {
    7280      if (Nval[i] == 0) {
    73         buf[i] = 0;
    7481        continue;
    7582      }
  • branches/czw_branch/20110406/Ohana/src/opihi/cmd.data/init.c

    r29938 r31606  
    130130int vstats           PROTO((int, char **));
    131131int vroll            PROTO((int, char **));
     132int vshift           PROTO((int, char **));
    132133int vpop             PROTO((int, char **));
    133134int vsmooth          PROTO((int, char **));
     
    274275  {1, "vmaxwell",     vmaxwell,         "fit a Maxwellian to a vector"},
    275276  {1, "vpop",         vpop,             "remove first element of a vector"},
    276   {1, "vroll",        vroll,            "roll vector elements"},
     277  {1, "vroll",        vroll,            "roll vector elements by 1 entry"},
     278  {1, "vshift",       vshift,           "shift vector elements by arbitrary amount"},
    277279  {1, "vsmooth",      vsmooth,          "Gaussian smooth of a vector"},
    278280  {1, "vstats",       vstats,           "statistics on a vector"},
  • branches/czw_branch/20110406/Ohana/src/opihi/dvo/Makefile

    r27594 r31606  
    8080$(SRC)/mextract.$(ARCH).o               \
    8181$(SRC)/mmextract.$(ARCH).o              \
     82$(SRC)/objectcoverage.$(ARCH).o         \
    8283$(SRC)/photcodes.$(ARCH).o              \
    8384$(SRC)/pmeasure.$(ARCH).o               \
  • branches/czw_branch/20110406/Ohana/src/opihi/dvo/avextract.c

    r30612 r31606  
    55  off_t i, j, n, m;
    66  int N, Npts, NPTS, last, next, state, Nfields, Nreturn, Ncstack, Nstack;
    7   int Nsecfilt, mode, VERBOSE;
     7  int Nsecfilt, mode, VERBOSE, needMeasures;
    88  char **cstack, name[1024];
    99  void *Signal;
     
    101101  }
    102102
     103  // check the requested fields : are all average/secfilt entries, or do we need measures?
     104  needMeasures = FALSE;
     105  for (i = 0; !needMeasures && (i < Nfields); i++) {
     106    if (fields[i].magMode == MAG_NONE) continue;
     107    if (fields[i].photcode == NULL) continue; // assert this?
     108    if (fields[i].photcode[0].type == PHOT_REF) needMeasures = TRUE;
     109    if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
     110  }
     111
    103112  // grab data from all selected sky regions
    104113  Signal = signal (SIGINT, handle_interrupt);
     
    107116    /* lock, load, unlock catalog */
    108117    catalog.filename = skylist[0].filename[i];
    109     catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     118    catalog.catflags = LOAD_AVES | LOAD_SECF;
     119    if (needMeasures) {
     120      catalog.catflags |= LOAD_MEAS;
     121    }
    110122    catalog.Nsecfilt = 0;
    111123
  • branches/czw_branch/20110406/Ohana/src/opihi/dvo/init.c

    r27594 r31606  
    4040int lightcurve      PROTO((int, char **));
    4141int mextract        PROTO((int, char **));
    42 int mmextract        PROTO((int, char **));
     42int mmextract       PROTO((int, char **));
     43int objectcoverage  PROTO((int, char **));
    4344int pcat            PROTO((int, char **));
    4445int photcodes       PROTO((int, char **));
     
    9293  {1, "mextract",    mextract,     "extract measure data values"},
    9394  {1, "mmextract",   mmextract,    "extract joined measurements"},
     95  {1, "objectcoverage", objectcoverage, "plot catalog boundaries"},
    9496  {1, "pcat",        skycat,       "plot catalog boundaries"},
    9597  {1, "photcodes",   photcodes,    "list photometry codes"},
  • branches/czw_branch/20110406/Ohana/src/photdbc/src/make_subcatalog.c

    r30616 r31606  
    7171    }
    7272
     73    // if the input catalog is an old type, generate the catID entries:
     74    if (catalog[0].catformat < DVO_FORMAT_PS1_V1) {
     75      subcatalog[0].average[Naverage].catID = catalog[0].catID;
     76    }
     77
    7378    minMag   = 32;
    7479    minSigma = 32;
     
    127132      subcatalog[0].measure[Nmeasure]        = catalog[0].measure[offset];
    128133      subcatalog[0].measure[Nmeasure].averef = Naverage;
     134
     135      // if the input catalog is an old type, generate the catID entries:
     136      if (catalog[0].catformat < DVO_FORMAT_PS1_V1) {
     137        subcatalog[0].measure[Nmeasure].catID = catalog[0].catID;
     138      }
     139
    129140      Nmeasure ++;
    130141      Nm ++;
  • branches/czw_branch/20110406/Ohana/src/relastro/src/UpdateObjects.c

    r31160 r31606  
    189189      coords.crval1 = R[0];
    190190      coords.crval2 = D[0];
    191       Tmean /= (float) N;
     191
     192      if (FIT_TARGET == TARGET_HIGH_SPEED) {
     193          Tmean = 0.5*(Tmax - Tmin);
     194      } else {
     195          Tmean /= (float) N;
     196      }
    192197     
    193198      XVERB = FALSE && (catalog[i].measure[m].dM < 0.01) && (N == 6) && (mode == FIT_PM_ONLY);
  • branches/czw_branch/20110406/Ohana/src/relastro/src/high_speed_catalogs.c

    r28184 r31606  
    1010
    1111  // load the current sky table (layout of all SkyRegions)
    12   sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     12  sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, FALSE, SKY_DEPTH, VERBOSE);
    1313  SkyTableSetFilenames (sky, CATDIR, "cpt");
    1414 
     
    3030    catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
    3131
    32     if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "w")) {
     32    if (!dvo_catalog_open (&catalog, skylist[0].regions[i], VERBOSE, "r")) {
    3333      fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
    3434      exit (1);
     
    4343    high_speed_objects (skylist[0].regions[i], &catalog);
    4444
    45     if (!UPDATE) {
    46       dvo_catalog_unlock (&catalog);
    47       dvo_catalog_free (&catalog);
    48       continue;
    49     }
    50    
    51     save_catalogs (&catalog, 1);
     45    dvo_catalog_unlock (&catalog);
     46    dvo_catalog_free (&catalog);
    5247  }
    5348 
  • branches/czw_branch/20110406/Ohana/src/relphot/include/relphot.h

    r30616 r31606  
    1111  unsigned int start;
    1212  unsigned int stop;
     13  short photcode;
    1314  float Mcal;
    1415  float dMcal;
     
    8586int    RELPHOT_GRID_BINNING;
    8687
    87 PhotCode      *photcode;
    88 int            PhotNsec;
    89 int            PhotSec;
     88int      *photseclist;
     89int      Nphotcodes;
     90PhotCode **photcodes;
     91// int            PhotSec;
     92// int            PhotNsec;
    9093
    9194PhotCode      *refPhotcode;
     95
     96int MaxDensityUse;
     97double MaxDensityValue;
    9298
    9399int AreaSelect;
     
    213219StatType      statsMosaicX        PROTO((Catalog *catalog));
    214220StatType      statsMosaicdM       PROTO((Catalog *catalog));
    215 StatType      statsStarN          PROTO((Catalog *catalog, int Ncatalog));
    216 StatType      statsStarS          PROTO((Catalog *catalog, int Ncatalog));
    217 StatType      statsStarX          PROTO((Catalog *catalog, int Ncatalog));
     221StatType      statsStarN          PROTO((Catalog *catalog, int Ncatalog, int Nsec, int seccode));
     222StatType      statsStarS          PROTO((Catalog *catalog, int Ncatalog, int Nsec));
     223StatType      statsStarX          PROTO((Catalog *catalog, int Ncatalog, int Nsec));
    218224void          wcatalog            PROTO((Catalog *catalog));
    219225void          wimages             PROTO((void));
     
    223229void relphot_usage (void);
    224230void relphot_help (int argc, char **argv);
     231
     232off_t getImageByID (off_t ID);
     233
     234int rationalize_mosaics ();
     235int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog);
     236
     237int populate_tiny_values (Catalog *catalog);
     238int free_tiny_values (Catalog *catalog);
  • branches/czw_branch/20110406/Ohana/src/relphot/src/GridOps.c

    r28241 r31606  
    348348  // sums for each star which touches as cell on both bases.
    349349
     350  int Nsecfilt = GetPhotcodeNsecfilt ();
     351  int thisCode = photcodes[0][0].code;
     352  int Nsec = GetPhotcodeNsec(thisCode);
     353
    350354  for (i = 0; i < Ngrid; i++) {
    351355   
     
    362366      mx = mlist[i][j];
    363367      c  = clist[i][j];
    364       n  = catalog[c].measure[mx].averef;
     368      n  = catalog[c].measureT[mx].averef;
    365369     
    366370      // if we have already visited this star, skip the stuff below
     
    369373
    370374      // skip stars marked as BAD
    371       if (catalog[c].average[n].flags & STAR_BAD) {
     375      if (catalog[c].secfilt[n*Nsecfilt+Nsec].flags & STAR_BAD) {
    372376        Nrel ++;
    373377        continue;
     
    389393
    390394        // skip measurements marked as BAD
    391         if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
     395        if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    392396          Nbad ++;
    393397          continue;
     
    410414        // select the color- and airmass-corrected observed magnitude for this star
    411415        // 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]);
    413         Msys = PhotCat (&catalog[c].measure[m]);
     416        Msys = PhotCatTiny (&catalog[c].measureT[m]);
    414417        if (isnan(Msys)) {
    415418          Nsys++;
     
    418421
    419422        // mag-error for this measurement
    420         Merr =  MAX (catalog[c].measure[m].dM, MIN_ERROR);
     423        Merr =  MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    421424
    422425        // Wsys = 1.0 / SQ(Merr);
     
    528531  if (!USE_GRID) return;
    529532
     533  int Nsecfilt = GetPhotcodeNsecfilt ();
     534
    530535  Nmax = Nlist[0];
    531536  for (i = 0; i < Ngrid; i++) {
     
    545550      c = clist[i][j];
    546551     
    547       if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
     552      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    548553        Nbad ++;
    549554        continue;
     
    565570      }
    566571     
    567       n = catalog[c].measure[m].averef;
    568       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     572      n = catalog[c].measureT[m].averef;
     573      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
    569574      if (isnan(Msys)) {
    570575        Nsys++;
     
    572577      }
    573578      list[N] = Msys - Mrel - Mcal - Mmos;
    574       dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
     579      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    575580      N++;
    576581    }
     
    613618  if (!USE_GRID) return;
    614619
     620  int Nsecfilt = GetPhotcodeNsecfilt ();
     621
    615622  N = 0;
    616623  for (i = 0; i < Ngrid; i++)
     
    630637      c = clist[i][j];
    631638     
    632       if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
     639      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    633640        Narea ++;
    634641        continue;
     
    641648      if (isnan(Mrel)) continue;
    642649
    643       n = catalog[c].measure[m].averef;
    644       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     650      n = catalog[c].measureT[m].averef;
     651      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
    645652
    646653      xlist[N] = Xmeas[c][m];
     
    704711  gfits_create_matrix (&header, &matrix);
    705712  gfits_modify (&header, "NEXTEND", OFF_T_FMT, 1,  Nimage + 3);
    706   gfits_modify (&header, "FILTER", "%s", 1, photcode[0].name);
     713  gfits_modify (&header, "FILTER", "%s", 1, photcodes[0][0].name);  // XXXX note that this expects a single photcode, enforced in initialize.d
    707714  gfits_modify_alt (&header, "COMMENT", "%S", 1, "Mosaic Photometry Grid Analysis");
    708715
     
    727734  theader.bitpix   = -32;
    728735  gfits_create_Theader (&theader, "IMAGE");
    729   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     736  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    730737  gfits_modify (&theader, "EXTNAME", "%s", 1, "MAG_OFFSET");
    731738  gfits_create_matrix  (&theader, &matrix);
     
    742749  /* save grid Nmeas values */
    743750  gfits_modify (&theader, "EXTNAME", "%s", 1, "NMEAS");
    744   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     751  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    745752  gfits_create_matrix  (&theader, &matrix);
    746753  for (i = 0; i < gridX; i++) {
     
    756763  /* save grid sigma values */
    757764  gfits_modify (&theader, "EXTNAME", "%s", 1, "SIGMA");
    758   gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     765  gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    759766  gfits_create_matrix  (&theader, &matrix);
    760767  for (i = 0; i < gridX; i++) {
     
    776783
    777784    gfits_modify (&theader, "EXTNAME", "%s", 1, camera.ccdname[N]);
    778     gfits_modify (&theader, "FILTER", "%s", 1, photcode[0].name);
     785    gfits_modify (&theader, "FILTER", "%s", 1, photcodes[0][0].name);
    779786    gfits_modify (&theader, "NX", "%d", 1, camera.Nx);
    780787    gfits_modify (&theader, "NY", "%d", 1, camera.Ny);
  • branches/czw_branch/20110406/Ohana/src/relphot/src/ImageOps.c

    r30616 r31606  
    11# include "relphot.h"
    2 
    3 # define USE_IMAGE_ID 1
    42
    53static off_t       **bin;     // link from catalog,measure to image         
     
    1210static off_t        Nimage;   // number of available images
    1311
    14 // if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted
    15 // index
    16 
    17 # if USE_IMAGE_ID
     12// to search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted index
    1813static off_t        *imageIDs; // list of all image IDs
    1914static off_t        *imageIdx; // list of index for image IDs
    20 # else
    21 static unsigned int *start;
    22 static unsigned int *stop;
    23 # endif
    2415
    2516Image *getimages (off_t *N) {
     
    4031  Nimage = N;
    4132
    42 # if USE_IMAGE_ID
    4333  ALLOCATE (imageIDs, off_t, Nimage);
    4434  ALLOCATE (imageIdx, off_t, Nimage);
     
    4939  }
    5040  llsortpair (imageIDs, imageIdx, Nimage);
    51 # else
    52   ALLOCATE (start,   unsigned, Nimage);
    53   ALLOCATE (stop,    unsigned, Nimage);
    54 
    55   for (i = 0; i < Nimage; i++) {
    56     start[i] = image[i].tzero - MAX(0.01*image[i].trate*image[i].NY, 1);
    57     stop[i]  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
    58   }
    59 # endif
    6041}
    6142
     
    6546  // use bisection to find the specified image ID
    6647
    67 # if USE_IMAGE_ID
    6848  off_t Nlo, Nhi, N;
    6949
     
    8262      return (imageIdx[N]);
    8363  }
    84 # endif
    8564
    8665  return (-1);
     
    128107}
    129108
    130 /* select all image equivalent to the current photcode */
     109/* select all image equivalent to the active photcode set */
    131110void findImages (Catalog *catalog, int Ncatalog) {
    132111
    133112  off_t j;
    134   int i, ecode;
    135 
    136   for (i = 0; i < Ncatalog; i++) {
     113  int i, ecode, Ns, found;
     114 
     115  int Nmatch = 0;
     116 for (i = 0; i < Ncatalog; i++) {
    137117    for (j = 0; j < catalog[i].Nmeasure; j++) {
    138       ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
    139       if (photcode[0].code != ecode) continue;
     118      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
     119      found = FALSE;
     120      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     121        if (ecode == photcodes[Ns][0].code) found = TRUE;
     122      }
     123      if (!found) continue;
    140124      matchImage (catalog, j, i);
    141     }
    142   }
    143 }
    144 
    145 int findCCD (off_t idx, off_t meas, int cat, Measure *measure) {
    146 
    147   int ccdnum;
     125      Nmatch ++;
     126    }
     127  }
     128 // fprintf (stderr, "matched %d detections to images\n", Nmatch);
     129}
     130
     131int findCCD (off_t idx, off_t meas, int cat, MeasureTiny *measure) {
     132
     133  int ccdnum, found, Ns, ecode;
    148134  double X, Y;
    149135  char *pname, *filter, *p, base[256];
     
    151137  /* identify the ccd on the basis of the photcode name */
    152138  pname = GetPhotcodeNamebyCode (image[idx].photcode);
    153   filter = photcode[0].name;
     139
     140  // XXX this seems quite terrible...
     141  ecode = GetPhotcodeEquivCodebyCode (measure[0].photcode);
     142  found = FALSE;
     143  for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     144    if (ecode == photcodes[Ns][0].code) found = TRUE;
     145  }
     146  if (!found) return (FALSE);
     147
     148  filter = photcodes[Ns][0].name;
    154149  sprintf (base, "%s.%s.", MOSAICNAME, filter);
    155150  if (strncmp (pname, base, strlen (base))) return (FALSE);
     
    170165
    171166  // old code to add this measurement to the grid cell for this chip
    172   // ave = measure[0].averef;
    173   // ra  = catalog[cat].average[ave].R - measure[0].dR / 3600.0;
    174   // dec = catalog[cat].average[ave].D - measure[0].dD / 3600.0;
     167  // ave = measureT[0].averef;
     168  // ra  = catalog[cat].averageT[ave].R - measureT[0].dR / 3600.0;
     169  // dec = catalog[cat].averageT[ave].D - measureT[0].dD / 3600.0;
    175170  // RD_to_XY (&X, &Y, ra, dec, &image[i].coords);
    176171
     
    183178}
    184179
    185 # if USE_IMAGE_ID
    186180void matchImage (Catalog *catalog, off_t meas, int cat) {
    187181
    188182  off_t idx, ID;
    189183  int status;
    190   Measure *measure;
     184  MeasureTiny *measure;
    191185 
    192   measure = &catalog[cat].measure[meas];
     186  measure = &catalog[cat].measureT[meas];
    193187
    194188  ID = measure[0].imageID;
     
    226220}
    227221
    228 # else
    229 // this is the time-based match
    230 void matchImage (Catalog *catalog, off_t meas, int cat) {
    231 
    232   off_t i;
    233   int status;
    234   Measure *measure;
    235  
    236   measure = &catalog[cat].measure[meas];
    237   for (i = 0; i < Nimage; i++) {
    238     if (image[0].photcode == -1) continue;
    239     if (measure[0].photcode != image[i].photcode) continue;
    240     if (measure[0].t < start[i]) continue;
    241     if (measure[0].t > stop[i]) continue;
    242    
    243     if (USE_GRID) {
    244       status = findCCD(i, meas, cat);
    245       if (!status) continue;
    246     }
    247 
    248     // index for (catalog, measure) -> image
    249     bin[cat][meas] = i;
    250 
    251     // index for image, Nentry -> catalog
    252     clist[i][Nlist[i]] = cat;
    253 
    254     // index for image, Nentry -> measure
    255     mlist[i][Nlist[i]] = meas;
    256     Nlist[i] ++;
    257 
    258     if (Nlist[i] == NLIST[i]) {
    259       NLIST[i] += 100;
    260       REALLOCATE (clist[i], off_t, NLIST[i]);
    261       REALLOCATE (mlist[i], off_t, NLIST[i]);
    262     }   
    263     return;
    264   }
    265   /*  fprintf (stderr, "can't find source image for this measurement: %d (%d)\n", measure[0].t, measure[0].photcode); */
    266 }
    267 # endif
    268 
    269222off_t getImageEntry (off_t meas, int cat) {
    270223
     
    307260
    308261  if (FREEZE_IMAGES) return;
     262
     263  int Nsecfilt = GetPhotcodeNsecfilt ();
    309264
    310265  if (PoorImages) {
     
    339294      c = clist[i][j];
    340295     
    341       if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
     296      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    342297          Nbad++;
    343298          continue;
     
    359314      }
    360315     
    361       n = catalog[c].measure[m].averef;
    362       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     316      n = catalog[c].measureT[m].averef;
     317      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
    363318      if (isnan(Msys)) {
    364319        Nsys++;
     
    366321      }
    367322      list[N] = Msys - Mrel - Mmos - Mgrid;
    368       dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
    369       if (catalog[c].measure[m].dM < IMFIT_SYS_SIGMA_LIM) {
     323      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
     324      if (catalog[c].measureT[m].dM < IMFIT_SYS_SIGMA_LIM) {
    370325        McalBright += list[N];
    371326        McalBright2 += SQ(list[N]);
     
    632587  return (stats);
    633588}
    634 
  • branches/czw_branch/20110406/Ohana/src/relphot/src/MosaicOps.c

    r30616 r31606  
    99static off_t   **imlist; /* mosaic -> image[] */
    1010static off_t   **bin;    /* catalog, measure -> mosaic */
     11
     12// list of mosaics associated with an image
     13static off_t   *mosimage;
    1114
    1215// list of mosaic associated with each image 
     
    3336  ALLOCATE (NIMLIST, off_t,   NMOSAIC);
    3437
     38  ALLOCATE (mosimage, off_t, Nimage); // mosaic to which image belongs
     39
    3540  /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no
    3641   * entry in the image table that represents this mosaic.  Instead, it is an
     
    4045  /* generate list of unique mosaics */
    4146  for (i = 0; i < Nimage; i++) {
     47    mosimage[i] = -1;
    4248
    4349    /* select valid mosaic images by photcode */
     
    5662      if (start > mosaic[j].stop)  continue;
    5763      found = TRUE;
     64
     65      // add reference from image to mosaic
     66      mosimage[i] = j;
    5867
    5968      /* add image to mosaic image list */
     
    7786    mosaic[Nmosaic].flags  = image[i].flags;
    7887    mosaic[Nmosaic].secz  = image[i].secz;
     88    mosaic[Nmosaic].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
    7989
    8090    /* add image to mosaic image list */
     
    8494    imlist[Nmosaic][0] = i;
    8595
     96    // add reference from image to mosaic
     97    mosimage[i] = Nmosaic;
     98   
    8699    Nmosaic ++;
    87100    if (Nmosaic == NMOSAIC) {
     
    250263int findMosaics (Catalog *catalog, int Ncatalog) {
    251264 
    252   int i, ecode;
     265  int i, ecode, found, Ns;
    253266  off_t j;
    254267
    255268  if (!MOSAIC_ZEROPT) return (FALSE);
    256269
     270  int Nmatch = 0;
    257271  for (i = 0; i < Ncatalog; i++) {
    258272    for (j = 0; j < catalog[i].Nmeasure; j++) {
    259273      if (TimeSelect) {
    260         if (catalog[i].measure[j].t < TSTART) continue;
    261         if (catalog[i].measure[j].t > TSTOP) continue;
    262       }
    263       ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[j].photcode);
    264       if (photcode[0].code != ecode) continue;
     274        if (catalog[i].measureT[j].t < TSTART) continue;
     275        if (catalog[i].measureT[j].t > TSTOP) continue;
     276      }
     277      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
     278      found = FALSE;
     279      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     280        if (ecode == photcodes[Ns][0].code) found = TRUE;
     281      }
     282      if (!found) continue;
    265283      matchMosaics (catalog, j, i);
    266     }
    267   }
     284      Nmatch ++;
     285    }
     286  }
     287  // fprintf (stderr, "matched %d detections to mosaics\n", Nmatch);
    268288  return (TRUE);
    269289}
     
    271291void matchMosaics (Catalog *catalog, off_t meas, int cat) {
    272292
    273   int i;
    274 
    275   for (i = 0; i < Nmosaic; i++) {
    276     if (catalog[cat].measure[meas].t < mosaic[i].start) continue;
    277     if (catalog[cat].measure[meas].t > mosaic[i].stop) continue;
     293  off_t idx, ID, mosID;
     294  MeasureTiny *measure;
     295
     296  measure = &catalog[cat].measureT[meas];
     297
     298  ID = measure[0].imageID;
     299  idx = getImageByID (ID);
     300  if (idx == -1) {
     301    if (VERBOSE2) fprintf (stderr, "missed measurement "OFF_T_FMT", %d\n", meas, cat);
     302    return;
     303  }
     304
     305  mosID = mosimage[idx];
     306  if (mosID < 0) {
     307    Image *image = getimage(idx);
     308    fprintf (stderr, "unmatched image %s\n", image[0].name);
     309    return;
     310  }
     311
     312  // test to check we got the right match:
     313  {
     314    Image *image = getimage(idx);
     315    unsigned int imageStart = image[0].tzero - MAX(0.01*image[0].trate*image[0].NY, 1);
     316    if (imageStart != mosaic[mosID].start) {
     317      fprintf (stderr, "error in image to mosaic match\n");
     318      abort();
     319    }
     320  }
     321
     322  bin[cat][meas] = mosID;
     323
     324  clist[mosID][Nlist[mosID]] = cat;
     325  mlist[mosID][Nlist[mosID]] = meas;
     326  Nlist[mosID] ++;
    278327   
    279 # ifdef GRID_V1
    280     if (USE_GRID) {
    281       ave = catalog[cat].measure[meas].averef;
    282       ra  = catalog[cat].average[ave].R - catalog[cat].measure[meas].dR / 3600.0;
    283       dec = catalog[cat].average[ave].D - catalog[cat].measure[meas].dD / 3600.0;
    284 
    285       /* X,Y always positive-definite in range 0,0 - dX, dY */
    286       RD_to_XY (&X, &Y, ra, dec, &mosaic[i].coords);
    287       setGridMeasure (meas, cat, X, Y);
    288     }
    289 # endif
    290 
    291     bin[cat][meas] = i;
    292 
    293     clist[i][Nlist[i]] = cat;
    294     mlist[i][Nlist[i]] = meas;
    295     Nlist[i] ++;
    296    
    297     if (Nlist[i] == NLIST[i]) {
    298       NLIST[i] += 100;
    299       REALLOCATE (clist[i], int,   NLIST[i]);
    300       REALLOCATE (mlist[i], off_t, NLIST[i]);
    301     }   
    302     return;
    303   }
    304   fprintf (stderr, "missed measurement\n");
     328  if (Nlist[mosID] == NLIST[mosID]) {
     329    NLIST[mosID] += 100;
     330    REALLOCATE (clist[mosID], int,   NLIST[mosID]);
     331    REALLOCATE (mlist[mosID], off_t, NLIST[mosID]);
     332  }     
    305333  return;
    306334}
     
    324352
    325353  off_t i, j, m, c, N, Nmax;
    326   int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys;
     354  int n, mark, bad, Nfew, Nbad, Ncal, Nrel, Ngrid, Nsys, Nsecfilt;
    327355  float Msys, Mrel, Mcal, Mgrid;
    328356  double *list, *dlist, *Mlist, *dMlist;
     
    334362
    335363  image = getimages (&N);
     364
     365  Nsecfilt = GetPhotcodeNsecfilt ();
    336366
    337367  if (PoorImages) {
     
    364394      c = clist[i][j];
    365395     
    366       if (catalog[c].measure[m].dbFlags & MEAS_BAD) {
     396      if (catalog[c].measureT[m].dbFlags & MEAS_BAD) {
    367397          Nbad ++;
    368398          continue;
     
    384414      }
    385415     
    386       n = catalog[c].measure[m].averef;
    387       Msys = PhotSys (&catalog[c].measure[m], &catalog[c].average[n], &catalog[c].secfilt[n*PhotNsec]);
     416      n = catalog[c].measureT[m].averef;
     417      Msys = PhotSysTiny (&catalog[c].measureT[m], &catalog[c].averageT[n], &catalog[c].secfilt[n*Nsecfilt]);
    388418      if (isnan(Msys)) {
    389419        Nsys++;
     
    391421      }
    392422      list[N]  = Msys - Mrel - Mcal - Mgrid;
    393       dlist[N] = MAX (catalog[c].measure[m].dM, MIN_ERROR);
     423      dlist[N] = MAX (catalog[c].measureT[m].dM, MIN_ERROR);
    394424      Mlist[N] = Msys;
    395425      dMlist[N] = list[N];
     
    433463}
    434464 
     465// When we rationalize the images/mosaics, we are driving the negative cloud images back
     466// to 0.0.  At the same time, we make a guess to the effective impact on all other images,
     467// driven by the coupling of common stars.
     468int rationalize_mosaics (Catalog *catalog, int Ncatalog) {
     469
     470  double *imageOffset, **starOffset;
     471  int **starNcount, *seclist;
     472  int **Slist, *NSlist, *NSLIST;
     473  int i, j, k, m, nMos, Ns, found;
     474
     475  off_t Nimage;
     476  Image *image;
     477
     478  // set a test value for now
     479  float CLOUD_TOLERANCE = 0.025;
     480
     481  if (!MOSAIC_ZEROPT) return (FALSE);
     482  if (FREEZE_MOSAICS) return (FALSE);
     483
     484  image = getimages (&Nimage);
     485
     486  ALLOCATE (imageOffset, double, Nmosaic);
     487
     488  ALLOCATE ( Slist, int *, Nmosaic); // array of calibrated star indexes on this mosaic
     489  ALLOCATE (NSlist, int,   Nmosaic); // number of stars on mosaic
     490  ALLOCATE (NSLIST, int,   Nmosaic); // number of Slist entries allocated
     491  memset (Slist, 0, Nmosaic*sizeof(int *));
     492
     493  // find the images / mosaics with negative clouds and save their offset
     494  for (i = 0; i < Nmosaic; i++) {
     495 
     496    NSlist[i] =   0;
     497    NSLIST[i] = 100;
     498    ALLOCATE (Slist[i], int, NSLIST[i]);
     499
     500    imageOffset[i] = 0.0;
     501
     502    if (VERBOSE2 && (fabs(mosaic[i].Mcal) < CLOUD_TOLERANCE)) {
     503      fprintf (stderr, "cloud-free: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     504    }
     505    if (VERBOSE2 && (mosaic[i].Mcal < -CLOUD_TOLERANCE)) {
     506      imageOffset[i] = -mosaic[i].Mcal;
     507      // NOTE the negative sign: down below, we are going to add in the negative of Mcal
     508      // to this image, and the propagated mean values for other images
     509      fprintf (stderr, "anti-clouds: %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     510    }
     511    if (VERBOSE2 && (mosaic[i].Mcal > CLOUD_TOLERANCE)) {
     512      fprintf (stderr, "cloudy    : %s : %f\n", image[imlist[i][0]].name, mosaic[i].Mcal);
     513    }
     514  }
     515
     516  int Nsecfilt = GetPhotcodeNsecfilt ();
     517  ALLOCATE (seclist, int, Nphotcodes);
     518  for (Ns = 0; Ns < Nphotcodes; Ns ++) {
     519    int thisCode = photcodes[Ns][0].code;
     520    seclist[Ns] = GetPhotcodeNsec(thisCode);
     521  }
     522
     523  // allocate an array for star offsets
     524  int Nstars = 0;
     525  int NSTARS = 1000;
     526  ALLOCATE (starOffset, double *, NSTARS);
     527  ALLOCATE (starNcount, int *,    NSTARS);
     528  memset (starOffset, 0, NSTARS*sizeof(double *));
     529  memset (starNcount, 0, NSTARS*sizeof(int *));
     530
     531  // find the mean offset for each star
     532  for (i = 0; i < Ncatalog; i++) {
     533    for (j = 0; j < catalog[i].Naverage; j++) {
     534      ALLOCATE (starOffset[Nstars], double, Nphotcodes);
     535      ALLOCATE (starNcount[Nstars], int,    Nphotcodes);
     536      memset (starOffset[Nstars], 0, Nphotcodes*sizeof(double));
     537      memset (starNcount[Nstars], 0, Nphotcodes*sizeof(int));
     538     
     539      m = catalog[i].averageT[j].measureOffset;
     540
     541      // determine the mosaic for each measurement
     542      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     543
     544        // skip unused measurements
     545        if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
     546
     547        // skip unused measurements
     548        int Nsec;
     549        int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     550        found = FALSE;
     551        for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {
     552          if (ecode == photcodes[Ns][0].code) {
     553            found = TRUE;
     554            break;
     555          }
     556        }
     557        if (!found) continue;
     558        Nsec = seclist[Ns];
     559
     560        // bad stars for this secfilt
     561        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
     562
     563        // skip REF measurements (not tied to an image)
     564        if (getImageEntry (m, i) < 0) continue;
     565
     566        // find the source of this measurement (skip unassigned measurements)
     567        nMos = bin[i][m];
     568        if (nMos == -1) continue;
     569
     570        if (mosaic[nMos].photcode != ecode) {
     571          fprintf (stderr, "*");
     572        }
     573
     574        assert (Ns >= 0);
     575        assert (Ns < Nphotcodes);
     576
     577        // accumulate the offsets from the negative cloud images (others have 0.0 value)
     578        starOffset[Nstars][Ns] += imageOffset[nMos];
     579        starNcount[Nstars][Ns] ++;
     580       
     581        // record the mosaic->star reference
     582        Slist[nMos][NSlist[nMos]] = Nstars;
     583        NSlist[nMos] ++;
     584        if (NSlist[nMos] == NSLIST[nMos]) {
     585          NSLIST[nMos] += 100;
     586          REALLOCATE (Slist[nMos], int, NSLIST[nMos]);
     587        }         
     588      }
     589      Nstars ++;
     590      if (Nstars == NSTARS) {
     591        NSTARS += 1000;
     592        REALLOCATE (starOffset, double *, NSTARS);
     593        REALLOCATE (starNcount, int *,    NSTARS);
     594        memset (&starOffset[NSTARS-1000], 0, 1000*sizeof(double *));
     595        memset (&starNcount[NSTARS-1000], 0, 1000*sizeof(int *));
     596      }
     597    }
     598  }
     599
     600  // find the mean offset of the images without negative clouds
     601  for (i = 0; i < Nmosaic; i++) {
     602
     603    found = FALSE;
     604    for (Ns = 0; !found && (Ns < Nphotcodes); Ns ++) {
     605      if (mosaic[i].photcode == photcodes[Ns][0].code) {
     606        found = TRUE;
     607        break;
     608      }
     609    }
     610    if (!found) {
     611      fprintf (stderr, "invalid photcode for mosaic?\n");
     612      abort();
     613    }
     614
     615    // a negative cloud image (cloud: Mcal > 0; anti-clouds: Mcal < 0; imageOffset = -Mcal)
     616    if (imageOffset[i] > 0.0) continue;
     617
     618    // we need to actually have cross-references to count
     619    if (NSlist[i] < 2) continue;
     620
     621    float dM = 0.0;
     622    for (j = 0; j < NSlist[i]; j++) {
     623      Nstars = Slist[i][j];
     624      if (starNcount[Nstars][Ns] > 1) {
     625        dM += (starOffset[Nstars][Ns] / starNcount[Nstars][Ns]);
     626      }
     627    }
     628    imageOffset[i] = dM / NSlist[i];
     629    // fprintf (stderr, "adjust image: %s : (%f %d) : %f\n", image[imlist[i][0]].name, dM, NSlist[i], imageOffset[i]);
     630  }
     631
     632  // for (i = 0; i < Nmosaic; i++) {
     633  //   fprintf (stderr, "correction: %s : %f\n", image[imlist[i][0]].name, imageOffset[i]);
     634  // }
     635
     636  // apply all offset values to the mosaics
     637  // find the images / mosaics with negative clouds and save their offset
     638  for (i = 0; i < Nmosaic; i++) {
     639    mosaic[i].Mcal += imageOffset[i];
     640  }
     641
     642  for (i = 0; i < Nstars; i++) {
     643    free (starOffset[i]);
     644    free (starNcount[i]);
     645  }
     646  free (starOffset);
     647  free (starNcount);
     648
     649  for (i = 0; i < Nmosaic; i++){
     650    free (Slist[i]);
     651  }
     652  free (NSlist);
     653  free (NSLIST);
     654  free (imageOffset);
     655  free (seclist);
     656  return (TRUE);
     657}
     658
    435659StatType statsMosaicM (Catalog *catalog) {
    436660
     
    524748    n++;
    525749  }
    526   fprintf (stderr, "Nmosaic: "OFF_T_FMT", n: "OFF_T_FMT"\n",  Nmosaic,  n);
     750  // fprintf (stderr, "Nmosaic: "OFF_T_FMT", n: "OFF_T_FMT"\n",  Nmosaic,  n);
    527751
    528752  liststats (list, dlist, n, &stats);
     
    563787void clean_mosaics () {
    564788
    565   off_t i, N, mark, Nmark;
     789  off_t i, N, mark, Nmark, Nscatter, Noffset;
    566790  double *mlist, *slist, *dlist;
    567791  double MaxOffset, MedOffset, MaxScatter;
     
    592816  fprintf (stderr, "Mrel: %f, dMrel: %f, Max Scatter: %f, Max Offset: %f\n", MedOffset, stats.median, MaxScatter, MaxOffset);
    593817 
    594   Nmark = 0;
     818  Nmark = Nscatter = Noffset = 0;
    595819  for (i = 0; i < Nmosaic; i++) {
    596820    mark = FALSE;
    597     mark = (mosaic[i].dMcal > MaxScatter) || (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset);
     821    if (mosaic[i].dMcal > MaxScatter) {
     822      mark = TRUE;
     823      Nscatter ++;
     824    }
     825    if (fabs(mosaic[i].Mcal - MedOffset) > MaxOffset) {
     826      mark = TRUE;
     827      Noffset ++;
     828    }
    598829    if (mark) {
    599830      Nmark ++;
     
    604835  }
    605836
    606   fprintf (stderr, OFF_T_FMT" mosaics marked poor\n",  Nmark);
     837  fprintf (stderr, OFF_T_FMT" mosaics marked poor ("OFF_T_FMT" scatter, "OFF_T_FMT" offset)\n",  Nmark, Nscatter, Noffset);
    607838  initstats (STATMODE);
    608839  free (mlist);
     
    640871      c = clist[i][j];
    641872     
    642       if (catalog[c].measure[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
    643 
    644       ave = catalog[c].measure[m].averef;
    645       xlist[N] = catalog[c].average[ave].R - catalog[c].measure[m].dR / 3600.0;
    646       ylist[N] = catalog[c].average[ave].D - catalog[c].measure[m].dD / 3600.0;
     873      if (catalog[c].measureT[m].dbFlags & (ID_MEAS_AREA | ID_MEAS_NOCAL)) continue;
     874
     875      ave = catalog[c].measureT[m].averef;
     876      xlist[N] = catalog[c].averageT[ave].R - catalog[c].measureT[m].dR / 3600.0;
     877      ylist[N] = catalog[c].averageT[ave].D - catalog[c].measureT[m].dD / 3600.0;
    647878      N++;
    648879    }
  • branches/czw_branch/20110406/Ohana/src/relphot/src/StarOps.c

    r29001 r31606  
    55static double *dlist;
    66
     7// When we rationalize the images/mosaics, we are driving the negative cloud images back
     8// to 0.0.  At the same time, we make a guess to the effective impact on all other images,
     9// driven by the coupling of common stars.  This array carries the impact of those offsets
     10// on each star
     11static double *Moffset;
     12
    713void initMrel (Catalog *catalog, int Ncatalog) {
    814
     
    1218  for (i = 0; i < Ncatalog; i++) {
    1319    for (j = 0; j < catalog[i].Naverage; j++) {
    14       Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
    15     }
    16   }
    17 
    18   ALLOCATE (list, double, MAX (1, Nmax));
    19   ALLOCATE (dlist, double, MAX (1, Nmax));
     20      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
     21    }
     22  }
     23
     24  ALLOCATE (list,    double, MAX (1, Nmax));
     25  ALLOCATE (dlist,   double, MAX (1, Nmax));
     26  ALLOCATE (Moffset, double, MAX (1, Nmax));
    2027
    2128
    2229float getMrel (Catalog *catalog, off_t meas, int cat) {
    2330
     31  int Nsec, Nsecfilt, photcode;
    2432  int ave;
    2533  float value;
    2634
    27   ave = catalog[cat].measure[meas].averef;
    28   if (catalog[cat].average[ave].flags & STAR_BAD) return (NAN); 
     35  ave = catalog[cat].measureT[meas].averef;
     36  photcode = catalog[cat].measureT[meas].photcode;
     37
     38  int ecode = GetPhotcodeEquivCodebyCode (photcode);
     39  Nsec = GetPhotcodeNsec(ecode);
     40  Nsecfilt = GetPhotcodeNsecfilt ();
     41
     42  // is this star OK?
     43  if (catalog[cat].secfilt[Nsecfilt*ave+Nsec].flags & STAR_BAD) return (NAN); 
    2944 
    30   value = catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;
     45  value = catalog[cat].secfilt[Nsecfilt*ave+Nsec].M;
    3146  return (value);
    3247}
     
    3954  StatType stats;
    4055
     56  int Nsecfilt = GetPhotcodeNsecfilt ();
    4157  Nfew = Nsys = Nbad = Ncal = Nmos = Ngrid = 0;
    4258
     
    4460    for (j = 0; j < catalog[i].Naverage; j++) {
    4561
    46       /* calculate the average value for a single star */
    47       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    48       m = catalog[i].average[j].measureOffset;
    49 
    50       N = 0;
    51       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    52         if (catalog[i].measure[m].dbFlags & MEAS_BAD) {
    53           Nbad ++;
    54           continue;
    55         }
    56         // XXX allow REF stars (no Image Entry) to be included in the calculation this
    57         // should be optionally set, and should allow for REF stars to be downweighted by
    58         // more than their reported errors.  how such info is carried is unclear...
    59         if (getImageEntry (m, i) < 0) {
    60           Mcal = Mmos = Mgrid = 0;
    61         } else {
    62           Mcal  = getMcal  (m, i);
    63           if (isnan(Mcal)) {
    64             Ncal ++;
     62      int Ns;
     63      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     64
     65        int thisCode = photcodes[Ns][0].code;
     66        int Nsec = GetPhotcodeNsec(thisCode);
     67
     68        /* calculate the average value for a single star */
     69
     70        // skip bad stars
     71        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
     72        m = catalog[i].averageT[j].measureOffset;
     73
     74        N = 0;
     75        for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     76          // skip measurements that do not match the current photcode
     77          int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     78          if (ecode != thisCode) { continue; }
     79
     80          if (catalog[i].measureT[m].dbFlags & MEAS_BAD) {
     81            Nbad ++;
    6582            continue;
    6683          }
    67           Mmos  = getMmos  (m, i);
    68           if (isnan(Mmos)) {
    69             Nmos ++;
     84          // XXX allow REF stars (no Image Entry) to be included in the calculation this
     85          // should be optionally set, and should allow for REF stars to be downweighted by
     86          // more than their reported errors.  how such info is carried is unclear...
     87          if (getImageEntry (m, i) < 0) {
     88            Mcal = Mmos = Mgrid = 0;
     89          } else {
     90            Mcal  = getMcal  (m, i);
     91            if (isnan(Mcal)) {
     92              Ncal ++;
     93              continue;
     94            }
     95            Mmos  = getMmos  (m, i);
     96            if (isnan(Mmos)) {
     97              Nmos ++;
     98              continue;
     99            }
     100            Mgrid = getMgrid (m, i);
     101            if (isnan(Mgrid)) {
     102              Ngrid++;
     103              continue;
     104            }
     105          }
     106
     107          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     108          if (isnan(Msys)) {
     109            Nsys++;
    70110            continue;
    71111          }
    72           Mgrid = getMgrid (m, i);
    73           if (isnan(Mgrid)) {
    74             Ngrid++;
    75             continue;
     112          list[N] = Msys - Mcal - Mmos - Mgrid;
     113          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     114
     115          // tie down reference photometry if the -refcode (code) option is selected
     116          if (refPhotcode) {
     117            if (GetPhotcodeEquivCodebyCode(catalog[i].measureT[m].photcode) == refPhotcode[0].equiv) {
     118              // increase the weight by a factor of 100:
     119              dlist[N] = 0.01*catalog[i].measureT[m].dM;
     120            }
    76121          }
    77         }
    78 
    79         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    80         if (isnan(Msys)) {
    81           Nsys++;
    82           continue;
    83         }
    84         list[N] = Msys - Mcal - Mmos - Mgrid;
    85         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    86 
    87         if (refPhotcode) {
    88           if (GetPhotcodeEquivCodebyCode(catalog[i].measure[m].photcode) == refPhotcode[0].equiv) {
    89             // increase the weight by a factor of 100:
    90             dlist[N] = 0.01*catalog[i].measure[m].dM;
    91           }
    92         }
    93         N++;
    94       }
    95 
    96       // when performing the grid analysis, STAR_TOOFEW will be set to 1;
    97 
    98       if (N <= STAR_TOOFEW) { /* too few measurements */
    99         catalog[i].average[j].flags |= ID_STAR_FEW;
    100         Nfew ++;
    101       } else {
    102         catalog[i].average[j].flags &= ~ID_STAR_FEW;
    103       }
    104 
    105       liststats (list, dlist, N, &stats);
    106 
    107       catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    108       catalog[i].secfilt[PhotNsec*j+PhotSec].dM = stats.sigma;
    109       catalog[i].secfilt[PhotNsec*j+PhotSec].Xm = (stats.Nmeas > 1) ? 100.0*log10(stats.chisq) : NAN_S_SHORT;
     122          N++;
     123        }
     124
     125        // when performing the grid analysis, STAR_TOOFEW will be set to 1;
     126        if (N <= STAR_TOOFEW) { /* too few measurements */
     127          catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_FEW;
     128          Nfew ++;
     129        } else {
     130          catalog[i].secfilt[Nsecfilt*j+Nsec].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      }
    110139    }
    111140  }
     
    122151  double *list, *dlist;
    123152  StatType stats;
     153  int Nsec, Nsecfilt, ecode;
     154
     155  Nsecfilt = GetPhotcodeNsecfilt ();
    124156
    125157  /* Nmeasure is now different, need to reallocate */
     
    127159  for (i = 0; i < Ncatalog; i++) {
    128160    for (j = 0; j < catalog[i].Naverage; j++) {
    129       Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
     161      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
    130162    }
    131163  }
     
    135167  for (i = 0; i < Ncatalog; i++) {
    136168    for (j = 0; j < catalog[i].Naverage; j++) {
    137 
    138169      /* skip stars already calibrated */
    139170      if (catalog[i].found[j]) continue; 
    140171
    141       N = 0;
    142       m = catalog[i].average[j].measureOffset;
    143       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    144         if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
    145         // XXX allow REF stars (no Image Entry) to be included in the calculation this
    146         // should be optionally set, and should allow for REF stars to be downweighted by
    147         // more than their reported errors.  how such info is carried is unclear...
    148         if (getImageEntry (m, i) < 0) {
    149           Mcal = Mmos = Mgrid = 0;
    150         } else {
    151           Mcal  = getMcal  (m, i);
    152           if (isnan(Mcal)) continue;
    153           Mmos  = getMmos  (m, i);
    154           if (isnan(Mmos)) continue;
    155           Mgrid = getMgrid (m, i);
    156           if (isnan(Mgrid)) continue;
    157         }
    158 
    159         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    160         list[N] = Msys - Mcal - Mmos - Mgrid;
    161         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    162         N++;
    163       }
    164       if (N < 1) continue;
    165 
    166       liststats (list, dlist, N, &stats);
    167       if (mark) catalog[i].found[j] = TRUE;
    168 
    169       /* use sigma or error in dM for output? */
    170       catalog[i].secfilt[PhotNsec*j+PhotSec].M  = stats.mean;
    171       catalog[i].secfilt[PhotNsec*j+PhotSec].dM = MAX (stats.error, stats.sigma);
    172       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].averageT[j].measureOffset;
     179        for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     180          // skip measurements that do not match the current photcode
     181          ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     182          if (ecode != thisCode) { continue; }
     183
     184          if (catalog[i].measureT[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 = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     201          list[N] = Msys - Mcal - Mmos - Mgrid;
     202          dlist[N] = MAX (catalog[i].measureT[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      }
    173215    }
    174216  }
     
    179221}
    180222
    181 // for each average object, set the average mags based on existing equiv photometry
     223// For each average object, set the average mags based on existing equiv photometry.
     224// NOTE: this function operates on the real Measure & Average structures, not the
     225// MeasureTiny & AverageTiny structures
    182226int setMave (Catalog *catalog, int Ncatalog) {
    183227
     
    202246  ALLOCATE (dlist, double, MAX (1, Nmax));
    203247
    204   Nsecfilt = catalog[0].Nsecfilt;
     248  Nsecfilt = GetPhotcodeNsecfilt ();
    205249
    206250# define PSFQUALSTATS 1
     
    220264          if (GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode) != Nc) continue;
    221265
    222           Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
     266          Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*Nsecfilt]);
    223267          if (isnan(Msys)) continue;
    224268
     
    321365    for (j = 0; j < catalog[i].Naverage; j++) {
    322366
    323       m = catalog[i].average[j].measureOffset;
    324       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    325         if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue;
     367      m = catalog[i].averageT[j].measureOffset;
     368      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     369        if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue;
    326370        Mcal  = getMcal  (m, i);
    327371        if (isnan(Mcal)) continue;
     
    330374        Mgrid = getMgrid (m, i);
    331375        if (isnan(Mgrid)) continue;
     376
     377        // set the output calibration
    332378        catalog[i].measure[m].Mcal = Mcal + Mmos + Mgrid;
    333379      }
     
    339385void clean_stars (Catalog *catalog, int Ncatalog) {
    340386
    341   int i, j, Ndel, Nave, Ntot, mark;
     387  int i, j, Ndel, Nave, Ntot, mark, Ns;
    342388  float dM, Xm;
    343389  double Chisq, MaxScatter, MaxChisq;
     
    354400  ALLOCATE (slist, double, Ntot);
    355401  ALLOCATE (dlist, double, Ntot);
    356   for (i = Ntot = 0; i < Ncatalog; i++) {
    357     for (j = 0; j < catalog[i].Naverage; j++) {
    358       if (catalog[i].average[j].flags & STAR_BAD) continue;
    359       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    360       if (Xm == -1) continue;
    361       Chisq = pow (10.0, 0.01*Xm);
    362       xlist[Ntot] = Chisq;
    363       slist[Ntot] = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    364       dlist[Ntot] = 1;
    365       Ntot ++;
    366     }
    367   }
     402
     403  int Nsecfilt = GetPhotcodeNsecfilt ();
     404
     405  // eliminate bad stars using the stats for a single secfilt at a time
     406  // XXX DEP replace average.flags with secfilt flags
     407  for (Ns = 0; Ns < Nphotcodes; Ns ++) {
     408   
     409    int thisCode = photcodes[Ns][0].code;
     410    int Nsec = GetPhotcodeNsec(thisCode);
     411
     412    for (i = Ntot = 0; i < Ncatalog; i++) {
     413      for (j = 0; j < catalog[i].Naverage; j++) {
     414        if ( catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD ) continue;
     415        Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     416        if (Xm == -1) continue;
     417        Chisq = pow (10.0, 0.01*Xm);
     418        xlist[Ntot] = Chisq;
     419        slist[Ntot] = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     420        dlist[Ntot] = 1;
     421        Ntot ++;
     422      }
     423    }
    368424 
    369   initstats ("MEAN");
    370   liststats (xlist, dlist, Ntot, &stats);
    371   MaxChisq = MAX (STAR_CHISQ, 2*stats.median);
    372   liststats (slist, dlist, Ntot, &stats);
    373   MaxScatter = MAX (STAR_SCATTER, 2*stats.median);
    374   fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq);
    375 
    376   Ndel = Nave = 0;
    377   for (i = 0; i < Ncatalog; i++) {
    378     for (j = 0; j < catalog[i].Naverage; j++) {
    379       dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    380       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    381       Chisq = pow (10.0, 0.01*Xm);
    382       mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
    383       if (mark) {
    384         catalog[i].average[j].flags |= ID_STAR_POOR;
    385         Ndel ++;
    386       } else {
    387         catalog[i].average[j].flags &= ~ID_STAR_POOR;
    388       }
    389       Nave ++;
    390     }
    391   }
    392   fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave);
    393   initstats (STATMODE);
     425    initstats ("MEAN");
     426    liststats (xlist, dlist, Ntot, &stats);
     427    MaxChisq = MAX (STAR_CHISQ, 2*stats.median);
     428    liststats (slist, dlist, Ntot, &stats);
     429    MaxScatter = MAX (STAR_SCATTER, 2*stats.median);
     430    fprintf (stderr, "Max Scatter: %f, Max Chisq: %f\n", MaxScatter, MaxChisq);
     431
     432    Ndel = Nave = 0;
     433    for (i = 0; i < Ncatalog; i++) {
     434      for (j = 0; j < catalog[i].Naverage; j++) {
     435        dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     436        Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     437        Chisq = pow (10.0, 0.01*Xm);
     438        mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
     439        if (mark) {
     440          catalog[i].secfilt[Nsecfilt*j+Nsec].flags |= ID_STAR_POOR;
     441          Ndel ++;
     442        } else {
     443          catalog[i].secfilt[Nsecfilt*j+Nsec].flags &= ~ID_STAR_POOR;
     444        }
     445        Nave ++;
     446      }
     447    }
     448    fprintf (stderr, "%d stars marked variable, %d total\n", Ndel, Nave);
     449    initstats (STATMODE);
     450  }
    394451  free (xlist);
    395452  free (slist);
     
    409466  int Ncal, Nmos, Ngrid, Nfew;
    410467
     468  int Nsecfilt = GetPhotcodeNsecfilt ();
     469
    411470  if (VERBOSE) fprintf (stderr, "marking poor measures\n");
    412471  /* Nmeasure is now different, need to reallocate */
     
    414473  for (i = 0; i < Ncatalog; i++) {
    415474    for (j = 0; j < catalog[i].Naverage; j++) {
    416       Nmax = MAX (Nmax, catalog[i].average[j].Nmeasure);
     475      Nmax = MAX (Nmax, catalog[i].averageT[j].Nmeasure);
    417476    }
    418477  }
     
    430489    for (j = 0; j < catalog[i].Naverage; j++) {
    431490
    432       /* skip bad stars to prevent them from becoming good (on inner sample) */
    433       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    434 
    435       /* on final processing, skip stars already measured */
    436       if (final && catalog[i].found[j]) continue; 
    437 
    438       /* accumulate list of valid measurements */
    439       m = catalog[i].average[j].measureOffset;
    440       N = 0;
    441       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    442         /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
    443         Mcal  = getMcal  (m, i);
    444         if (isnan(Mcal)) { Ncal ++; continue; }
    445         Mmos  = getMmos  (m, i);
    446         if (isnan(Mmos)) { Nmos ++; continue; }
    447         Mgrid = getMgrid (m, i);
    448         if (isnan(Mgrid)) { Ngrid ++; continue; }
    449 
    450         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    451         list[N] = Msys - Mcal - Mmos - Mgrid;
    452         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    453         N++;
    454       }
    455       if (N <= TOOFEW) { Nfew ++; continue; }
    456 
    457       /* 3-sigma clip based on stats of inner 50% */
    458 
    459       // calculated mean of inner 50%
    460       initstats ("INNER_MEAN");
    461       liststats (list, dlist, N, &stats);
    462       stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */
    463 
    464       // ignore entries > 3sigma from inner mean
    465       for (k = m = 0; k < N; k++) {
    466         if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) {
    467           list[m] = list[k];
    468           m++;
    469         }
    470       }
    471       // recalculate the mean & sigma of the accepted measurements
    472       initstats ("MEAN");
    473       liststats (list, dlist, m, &stats);
    474       stats.sigma = MAX (MIN_ERROR, stats.sigma);
    475 
    476       /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */
    477       image_bad = IMAGE_BAD;
    478       IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
    479       m = catalog[i].average[j].measureOffset;
    480       N = 0;
    481       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
    482         /* if (catalog[i].measure[m].dbFlags & MEAS_BAD) continue; */
    483         Mcal  = getMcal  (m, i);
    484         if (isnan(Mcal)) continue;
    485         Mmos  = getMmos  (m, i);
    486         if (isnan(Mmos)) continue;
    487         Mgrid = getMgrid (m, i);
    488         if (isnan(Mgrid)) continue;
    489 
    490         Msys = PhotSys (&catalog[i].measure[m], &catalog[i].average[j], &catalog[i].secfilt[j*PhotNsec]);
    491         list[N] = Msys - Mcal - Mmos - Mgrid;
    492         dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
    493         ilist[N] = m;
    494         N++;
    495         Nave ++;
    496       }
    497       if (N < TOOFEW) continue;
    498 
    499       /* mark bad measures (> 3 sigma deviant) */
    500       for (k = 0; k < N; k++) {
    501         if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) {
    502           catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
    503           Ndel ++;
    504         }
    505       }
    506       IMAGE_BAD = image_bad;
     491      int Ns;
     492      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     493       
     494        /* on final processing, skip stars already measured */
     495        if (final && catalog[i].found[j]) continue; 
     496
     497        int thisCode = photcodes[Ns][0].code;
     498        int Nsec = GetPhotcodeNsec(thisCode);
     499       
     500        /* skip bad stars to prevent them from becoming good (on inner sample) */
     501        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
     502
     503        /* accumulate list of valid measurements */
     504        m = catalog[i].averageT[j].measureOffset;
     505        N = 0;
     506        for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     507          // skip measurements that do not match the current photcode
     508          int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     509          if (ecode != thisCode) { continue; }
     510
     511          /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */
     512          Mcal  = getMcal  (m, i);
     513          if (isnan(Mcal)) { Ncal ++; continue; }
     514          Mmos  = getMmos  (m, i);
     515          if (isnan(Mmos)) { Nmos ++; continue; }
     516          Mgrid = getMgrid (m, i);
     517          if (isnan(Mgrid)) { Ngrid ++; continue; }
     518
     519          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     520          list[N] = Msys - Mcal - Mmos - Mgrid;
     521          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     522          N++;
     523        }
     524        if (N <= TOOFEW) { Nfew ++; continue; }
     525
     526        /* 3-sigma clip based on stats of inner 50% */
     527
     528        // calculated mean of inner 50%
     529        initstats ("INNER_MEAN");
     530        liststats (list, dlist, N, &stats);
     531        stats.sigma = MAX (MIN_ERROR, stats.sigma); /* if measurements agree too well, sigma -> 0.0 */
     532
     533        // ignore entries > 3sigma from inner mean
     534        for (k = m = 0; k < N; k++) {
     535          if (fabs (list[k] - stats.median) < NSIGMA_CLIP*stats.sigma) {
     536            list[m] = list[k];
     537            m++;
     538          }
     539        }
     540        // recalculate the mean & sigma of the accepted measurements
     541        initstats ("MEAN");
     542        liststats (list, dlist, m, &stats);
     543        stats.sigma = MAX (MIN_ERROR, stats.sigma);
     544
     545        /* apply to list of all relevant measurements, including IMAGE_POOR & IMAGE_FEW */
     546        image_bad = IMAGE_BAD;
     547        IMAGE_BAD = ID_IMAGE_PHOTOM_NOCAL;
     548        m = catalog[i].averageT[j].measureOffset;
     549        N = 0;
     550        for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     551          // skip measurements that do not match the current photcode
     552          int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     553          if (ecode != thisCode) { continue; }
     554
     555          /* if (catalog[i].measureT[m].dbFlags & MEAS_BAD) continue; */
     556          Mcal  = getMcal  (m, i);
     557          if (isnan(Mcal)) continue;
     558          Mmos  = getMmos  (m, i);
     559          if (isnan(Mmos)) continue;
     560          Mgrid = getMgrid (m, i);
     561          if (isnan(Mgrid)) continue;
     562
     563          Msys = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]);
     564          list[N] = Msys - Mcal - Mmos - Mgrid;
     565          dlist[N] = MAX (catalog[i].measureT[m].dM, MIN_ERROR);
     566          ilist[N] = m;
     567          N++;
     568          Nave ++;
     569        }
     570        if (N < TOOFEW) continue;
     571
     572        /* mark bad measures (> 3 sigma deviant) */
     573        for (k = 0; k < N; k++) {
     574          if (fabs (list[k] - stats.median) > NSIGMA_REJECT*stats.sigma) {
     575            catalog[i].measureT[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
     576            if (final) {
     577              // for the final pass, we have a duplicate set of values in measure and measureT
     578              catalog[i].measure[ilist[k]].dbFlags |= ID_MEAS_POOR_PHOTOM;
     579            }
     580            Ndel ++;
     581          }
     582        }
     583        IMAGE_BAD = image_bad;
     584      }
    507585    }
    508586  }
     
    513591}
    514592
    515 StatType statsStarN (Catalog *catalog, int Ncatalog) {
     593StatType statsStarN (Catalog *catalog, int Ncatalog, int Nsec, int seccode) {
    516594
    517595  off_t j, k, m, Ntot;
     
    520598  float Mcal, Mmos, Mgrid;
    521599  StatType stats;
     600  // int N1, N2, N3, N4, N0;
     601  // N1 = N2 = N3 = N4 = N0 = 0;
     602
     603  int Nsecfilt = GetPhotcodeNsecfilt ();
    522604
    523605  Ntot = 0;
     
    534616
    535617      /* calculate the average value for a single star */
    536       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    537       m = catalog[i].average[j].measureOffset;
     618      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) { continue;  }
     619      m = catalog[i].averageT[j].measureOffset;
    538620
    539621      N = 0;
    540       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     622      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
     623        int ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     624        if (ecode != seccode) { continue;}
    541625        Mcal = getMcal  (m, i);
    542         if (isnan(Mcal)) continue;
     626        if (isnan(Mcal)) { continue;}
    543627        Mmos = getMmos  (m, i);
    544         if (isnan(Mmos)) continue;
     628        if (isnan(Mmos)) { continue; }
    545629        Mgrid = getMgrid (m, i);
    546         if (isnan(Mgrid)) continue;
     630        if (isnan(Mgrid)) { continue;}
    547631        N++;
    548632      }
     
    554638  }
    555639
     640  // fprintf (stderr, "N1: %d, N2: %d, N3: %d, N4: %d, N0: %d\n", N1, N2, N3, N4, N0);
    556641  liststats (list, dlist, n, &stats);
    557642  free (list);
     
    560645}
    561646
    562 StatType statsStarX (Catalog *catalog, int Ncatalog) {
     647// stats for a single secfilt at a time
     648StatType statsStarX (Catalog *catalog, int Ncatalog, int Nsec) {
    563649
    564650  off_t j, Ntot;
     
    567653  StatType stats;
    568654
     655  int Nsecfilt = GetPhotcodeNsecfilt ();
     656
    569657  Ntot = 0;
    570658  for (i = 0; i < Ncatalog; i++) {
     
    580668
    581669      /* calculate the average value for a single star */
    582       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    583 
    584       Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     670      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
     671       
     672      Xm = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
    585673      if (Xm == NAN_S_SHORT) continue;
    586674      list[n] = pow (10.0, 0.01*Xm);
     
    596684}
    597685
    598 StatType statsStarS (Catalog *catalog, int Ncatalog) {
     686StatType statsStarS (Catalog *catalog, int Ncatalog, int Nsec) {
    599687
    600688  int i, n;
     
    604692  StatType stats;
    605693
     694  int Nsecfilt = GetPhotcodeNsecfilt ();
     695
    606696  Ntot = 0;
    607697  for (i = 0; i < Ncatalog; i++) {
     
    617707
    618708      /* calculate the average value for a single star */
    619       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    620 
    621       dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     709      if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
     710
     711      dM = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
    622712      list[n] = dM;
    623713      dlist[n] = 1;
     
    644734  ALLOCATE (Mlist, double, NBIN);
    645735
    646   for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
    647   bzero (Mlist, NBIN*sizeof(double));
    648   for (i = 0; i < Ncatalog; i++) {
    649     for (j = 0; j < catalog[i].Naverage; j++) {
    650       if (catalog[i].average[j].flags & STAR_BAD) continue; 
    651       dMrel = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    652       bin = dMrel / 0.00025;
    653       bin = MAX (0, MIN (NBIN-1, bin));
    654       Mlist[bin] += 1.0;
    655     }
    656   }
    657 
    658   plot_defaults (&graphdata);
    659   graphdata.style = 1;
    660   plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT);
    661 
     736  int Nsecfilt = GetPhotcodeNsecfilt ();
     737
     738  int Ns;
     739  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     740
     741    int thisCode = photcodes[Ns][0].code;
     742    int Nsec = GetPhotcodeNsec(thisCode);
     743
     744    for (i = 0; i < NBIN; i++) xlist[i] = 0.00025*i;
     745    bzero (Mlist, NBIN*sizeof(double));
     746    for (i = 0; i < Ncatalog; i++) {
     747      for (j = 0; j < catalog[i].Naverage; j++) {
     748        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue; 
     749        dMrel = catalog[i].secfilt[Nsecfilt*j+Nsec].dM;
     750        bin = dMrel / 0.00025;
     751        bin = MAX (0, MIN (NBIN-1, bin));
     752        Mlist[bin] += 1.0;
     753      }
     754    }
     755
     756    plot_defaults (&graphdata);
     757    graphdata.style = 1;
     758    plot_list (&graphdata, xlist, Mlist, NBIN, "dMrel hist", "%s.dMhist.png", OUTROOT);
     759  }
    662760  free (xlist);
    663761  free (Mlist);
     
    671769  Graphdata graphdata;
    672770
     771  int Nsecfilt = GetPhotcodeNsecfilt ();
     772
    673773  Ntotal = 0;
    674774  for (i = 0; i < Ncatalog; i++) Ntotal += catalog[i].Naverage;
     
    677777  ALLOCATE (ylist, double, Ntotal);
    678778
    679   N = 0;
    680   for (i = 0; i < Ncatalog; i++) {
    681     for (j = 0; j < catalog[i].Naverage; j++) {
    682       if (catalog[i].average[j].flags & STAR_BAD) continue;
    683       xlist[N] = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    684       value    = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    685       if (value == NAN_S_SHORT) continue;
    686       ylist[N] = 0.01*value;
    687       N++;
    688     }
    689   }
    690 
    691   plot_defaults (&graphdata);
    692   graphdata.ymin = -3.0;
    693   plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT);
     779  int Ns;
     780  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     781
     782    int thisCode = photcodes[Ns][0].code;
     783    int Nsec = GetPhotcodeNsec(thisCode);
     784
     785    N = 0;
     786    for (i = 0; i < Ncatalog; i++) {
     787      for (j = 0; j < catalog[i].Naverage; j++) {
     788        if (catalog[i].secfilt[Nsecfilt*j+Nsec].flags & STAR_BAD) continue;
     789        xlist[N] = catalog[i].secfilt[Nsecfilt*j+Nsec].M;
     790        value    = catalog[i].secfilt[Nsecfilt*j+Nsec].Xm;
     791        if (value == NAN_S_SHORT) continue;
     792        ylist[N] = 0.01*value;
     793        N++;
     794      }
     795    }
     796
     797    plot_defaults (&graphdata);
     798    graphdata.ymin = -3.0;
     799    plot_list (&graphdata, xlist, ylist, N, "chisq", "%s.chisq.png", OUTROOT);
     800  }
     801
    694802  free (xlist);
    695803  free (ylist);
     
    716824  for (i = 0; i < Ncatalog; i++) {
    717825    for (j = 0; j < catalog[i].Naverage; j++) {
    718       xlist[N] = catalog[i].average[j].R;
    719       ylist[N] = catalog[i].average[j].D;
     826      xlist[N] = catalog[i].averageT[j].R;
     827      ylist[N] = catalog[i].averageT[j].D;
    720828      N++;
    721829    }
  • branches/czw_branch/20110406/Ohana/src/relphot/src/args.c

    r31160 r31606  
    128128  }
    129129
     130  MaxDensityUse = FALSE;
     131  if ((N = get_argument (argc, argv, "-max-density"))) {
     132    remove_argument (N, &argc, argv);
     133    MaxDensityValue = atof(argv[N]);
     134    remove_argument (N, &argc, argv);
     135    MaxDensityUse = TRUE;
     136  }
     137
    130138  SHOW_PARAMS = FALSE;
    131139  if ((N = get_argument (argc, argv, "-params"))) {
  • branches/czw_branch/20110406/Ohana/src/relphot/src/bcatalog.c

    r31160 r31606  
    11# include "relphot.h"
     2
     3extern double drand48();
     4
     5int CopyAverageTiny (AverageTiny *averageT, Average *average) {
     6
     7  averageT[0].R     = average[0].R;
     8  averageT[0].D     = average[0].D;
     9  averageT[0].flags = average[0].flags;
     10  averageT[0].Nmeasure      = average[0].Nmeasure;
     11  averageT[0].measureOffset = average[0].measureOffset;
     12
     13  // make Nmeasure & measureOffset optional?
     14
     15  return (TRUE);
     16}
     17
     18int CopyMeasureTiny (MeasureTiny *measureT, Measure *measure) {
     19
     20  measureT[0].dR       = measure[0].dR;
     21  measureT[0].dD       = measure[0].dD;
     22  measureT[0].M        = measure[0].M;
     23  measureT[0].Mcal     = measure[0].Mcal;
     24  measureT[0].dM       = measure[0].dM;
     25  measureT[0].airmass  = measure[0].airmass;
     26  measureT[0].Xccd     = measure[0].Xccd;
     27  measureT[0].Yccd     = measure[0].Yccd;
     28  measureT[0].t        = measure[0].t;
     29  measureT[0].dt       = measure[0].dt;
     30  measureT[0].averef   = measure[0].averef;
     31  measureT[0].imageID  = measure[0].imageID;
     32  measureT[0].dbFlags  = measure[0].dbFlags;
     33  measureT[0].photcode = measure[0].photcode;
     34
     35  return (TRUE);
     36}
    237
    338int bcatalog (Catalog *subcatalog, Catalog *catalog) {
    439 
    540  off_t i, j, offset;
    6   int ecode;
     41  int ecode, found, Ns;
    742  off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm;
    843  float mag;
    944  int Ncode, Ntime, Ndophot, Nmag, Nsigma, Nimag, Nfew, Ngalaxy, Npsfqf;
    1045
    11   // XXX PhotNsec as a global is a bad idea; either get it from catalog
    12   // or get it from:
    13   // Nsecfilt = GetPhotcodeNsecfilt ();
    14   // assert (catalog[0].Nsecfilt == Nsecfilt);
     46  int Nsecfilt = GetPhotcodeNsecfilt ();
     47  assert (Nsecfilt == catalog[0].Nsecfilt);
    1548
    1649  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
     
    1851  NAVERAGE = 50;
    1952  NMEASURE = 1000;
    20   ALLOCATE (subcatalog[0].average, Average, NAVERAGE);
    21   ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*PhotNsec);
    22   ALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
     53  ALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
     54  ALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE);
     55  ALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
    2356  Nmeasure = Naverage = 0;
    2457
     
    3063
    3164    /* start with all stars good */
    32     subcatalog[0].average[Naverage] = catalog[0].average[i];
    33     subcatalog[0].average[Naverage].measureOffset = Nmeasure;
    34     for (j = 0; j < PhotNsec; j++) {
    35       subcatalog[0].secfilt[PhotNsec*Naverage+j] = catalog[0].secfilt[PhotNsec*i+j];
     65    CopyAverageTiny (&subcatalog[0].averageT[Naverage], &catalog[0].average[i]);
     66    subcatalog[0].averageT[Naverage].measureOffset = Nmeasure;
     67
     68    for (j = 0; j < Nsecfilt; j++) {
     69      subcatalog[0].secfilt[Nsecfilt*Naverage+j] = catalog[0].secfilt[Nsecfilt*i+j];
    3670    }
    3771
    3872    if (RESET) {
    39       subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].M  = NAN;
    40       subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].dM = NAN;
    41       subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW;
    42       subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR;
     73      int Ns;
     74      for (Ns = 0; Ns < Nphotcodes; Ns++) {
     75
     76        int thisCode = photcodes[Ns][0].code;
     77        int Nsec = GetPhotcodeNsec(thisCode);
     78
     79        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].M  = NAN;
     80        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].dM = NAN;
     81        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~ID_STAR_FEW;
     82        subcatalog[0].secfilt[Nsecfilt*Naverage+Nsec].flags &= ~ID_STAR_POOR;
     83      }
    4384    }
    4485
     
    5293      /* select measurements by photcode */
    5394      ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[offset].photcode);
    54       if (ecode != photcode[0].code) { Ncode ++; continue; }
     95      found = FALSE;
     96      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     97        if (ecode == photcodes[Ns][0].code) found = TRUE;
     98      }
     99      if (!found) {
     100        Ncode ++;
     101        continue;
     102      }
    55103
    56104      /* select measurements by time */
     
    61109
    62110      /* select measurements by quality */
    63       // XXX ignore this criterion for REF measurements?
    64       // XXX chnage this to select by bitflags
    65111      if (DophotSelect && ((catalog[0].measure[offset].photFlags >> 16) != DophotValue)) { Ndophot ++; continue; }
    66112
     
    70116      // check for galaxies
    71117      if (!isnan(catalog[0].measure[offset].Map)) {
    72           if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) {
    73               nEXT ++;
    74           } else {
    75               nPSF ++;
    76           }
     118        if (catalog[0].measure[offset].M - catalog[0].measure[offset].Map > 0.15) {
     119          nEXT ++;
     120        } else {
     121          nPSF ++;
     122        }
    77123      }
    78124
     
    91137      }
    92138
    93       subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    94       subcatalog[0].measure[Nmeasure]        = catalog[0].measure[offset];
    95       subcatalog[0].measure[Nmeasure].averef = Naverage;
     139      CopyMeasureTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
     140      subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
     141      subcatalog[0].measureT[Nmeasure].averef = Naverage;
    96142      if (RESET) {
    97         subcatalog[0].measure[Nmeasure].Mcal = 0;
    98         subcatalog[0].measure[Nmeasure].dbFlags &= 0xff00;
    99         subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
    100         subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
    101         subcatalog[0].measure[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
     143        subcatalog[0].measureT[Nmeasure].Mcal = 0;
     144        subcatalog[0].measureT[Nmeasure].dbFlags &= 0xff00;
     145        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
     146        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_AREA;
     147        subcatalog[0].measureT[Nmeasure].dbFlags &= ~ID_MEAS_NOCAL;
    102148      }
    103149      Nmeasure ++;
     
    105151      if (Nmeasure == NMEASURE) {
    106152        NMEASURE += 1000;
    107         REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
     153        REALLOCATE (subcatalog[0].measureT, MeasureTiny, NMEASURE);
    108154      }
    109155    }
     
    122168      continue;
    123169    }
    124     subcatalog[0].average[Naverage].Nmeasure = Nm;
     170    subcatalog[0].averageT[Naverage].Nmeasure = Nm;
    125171    Naverage ++;
    126172    if (Naverage == NAVERAGE) {
    127173      NAVERAGE += 50;
    128       REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
    129       REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*PhotNsec);
    130     }
    131   }
    132   REALLOCATE (subcatalog[0].average, Average, MAX (Naverage, 1));
    133   REALLOCATE (subcatalog[0].measure, Measure, MAX (Nmeasure, 1));
    134   REALLOCATE (subcatalog[0].secfilt, SecFilt, PhotNsec*MAX (Naverage, 1));
     174      REALLOCATE (subcatalog[0].averageT, AverageTiny, NAVERAGE);
     175      REALLOCATE (subcatalog[0].secfilt,  SecFilt,     NAVERAGE*Nsecfilt);
     176    }
     177  }
     178  REALLOCATE (subcatalog[0].averageT, AverageTiny, MAX (Naverage, 1));
     179  REALLOCATE (subcatalog[0].measureT, MeasureTiny, MAX (Nmeasure, 1));
     180  REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1));
    135181  subcatalog[0].Naverage = Naverage;
    136182  subcatalog[0].Nmeasure = Nmeasure;
    137183  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
    138184  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
    139   assert (PhotNsec == catalog[0].Nsecfilt);
     185
     186  // limit the total number of stars in the catalog
     187  if (MaxDensityUse) {
     188    LimitDensityCatalog (subcatalog, catalog);
     189  }
    140190
    141191  if (VERBOSE) {
     
    147197  return (TRUE);
    148198}
     199
     200int LimitDensityCatalog (Catalog *subcatalog, Catalog *catalog) {
     201
     202  Catalog tmpcatalog;
     203
     204  double Rmin, Rmax, Dmin, Dmax;
     205
     206  int Nsecfilt = GetPhotcodeNsecfilt ();
     207
     208  gfits_scan (&catalog[0].header, "RA0",  "%lf", 1, &Rmin);
     209  gfits_scan (&catalog[0].header, "DEC0", "%lf", 1, &Dmin);
     210  gfits_scan (&catalog[0].header, "RA1",  "%lf", 1, &Rmax);
     211  gfits_scan (&catalog[0].header, "DEC1", "%lf", 1, &Dmax);
     212
     213  if (VERBOSE2) fprintf (stderr, "extracting from catalog covering region %f,%f to %f,%f\n", Rmin, Dmin, Rmax, Dmax);
     214
     215  float AREA = fabs(Dmax - Dmin) * fabs(Rmax - Rmin) * cos (0.5*RAD_DEG*(Dmax + Dmin));
     216  assert (AREA > 0);
     217
     218  off_t Nmax = MaxDensityValue * AREA;
     219  if (subcatalog[0].Naverage <= Nmax) {
     220    if (VERBOSE) {
     221      fprintf (stderr, "subcatalog has less than the max density\n");
     222    }
     223    return (TRUE);
     224  }
     225
     226  off_t Naverage = subcatalog[0].Naverage;
     227
     228  // select a random subset of Nmax stars from subcatalog using Fisher-Yates
     229
     230  // we are going to select Nmax entries by generating a random-sorted index list
     231  off_t *index, tmp, i, j, ave;
     232  ALLOCATE (index, off_t, Naverage);
     233  for (i = 0; i < Naverage; i++) {
     234    index[i] = i;
     235  }
     236  for (i = 0; i < Naverage; i++) {
     237    j = (Naverage - i) * drand48() + i; // a number between i and Naverage
     238    tmp = index[j];
     239    index[j] = index[i];
     240    index[i] = tmp;
     241  }
     242
     243  // count the number of measurements this selection will yield
     244  off_t NMEASURE = 0;
     245  for (i = 0; i < Nmax; i++) {
     246    ave = index[i];
     247    NMEASURE += subcatalog[0].averageT[ave].Nmeasure;
     248  }
     249
     250  // allocate the output data
     251  ALLOCATE (tmpcatalog.averageT, AverageTiny, Nmax);
     252  ALLOCATE (tmpcatalog.measureT, MeasureTiny, NMEASURE);
     253  ALLOCATE (tmpcatalog.secfilt,  SecFilt, Nmax * Nsecfilt);
     254
     255  off_t Nmeasure = 0;
     256
     257  // copy the Nmax selected entries from subcatalog to tmpcatalog (adjusting links)
     258  for (i = 0; i < Nmax; i++) {
     259    ave = index[i];
     260    tmpcatalog.averageT[i] = subcatalog[0].averageT[ave];
     261    tmpcatalog.averageT[i].measureOffset = Nmeasure;
     262    for (j = 0; j < tmpcatalog.averageT[i].Nmeasure; j++) {
     263      off_t offset = subcatalog[0].averageT[ave].measureOffset + j;
     264      tmpcatalog.measureT[Nmeasure] = subcatalog[0].measureT[offset];
     265      tmpcatalog.measureT[Nmeasure].averef = i;
     266      Nmeasure ++;
     267    }
     268  }
     269
     270  if (VERBOSE) {
     271    fprintf (stderr, "limited to "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measures) for catalog %s\n",
     272             Nmax, subcatalog[0].Naverage, Nmeasure, subcatalog[0].Nmeasure,  catalog[0].filename);
     273  }
     274
     275  free (subcatalog[0].averageT);
     276  free (subcatalog[0].measureT);
     277  free (subcatalog[0].secfilt);
     278
     279  subcatalog[0].averageT = tmpcatalog.averageT;
     280  subcatalog[0].measureT = tmpcatalog.measureT;
     281  subcatalog[0].secfilt = tmpcatalog.secfilt;
     282  subcatalog[0].Naverage = Nmax;
     283  subcatalog[0].Nmeasure = Nmeasure;
     284  subcatalog[0].Nsecfilt = catalog[0].Nsecfilt;
     285  subcatalog[0].Nsecf_mem = Naverage * catalog[0].Nsecfilt;
     286
     287  return (TRUE);
     288}
     289
     290// for the cases where we are not using a subset of the data, we still need to have a copy of these fields
     291int populate_tiny_values (Catalog *catalog) {
     292
     293  off_t i;
     294
     295  ALLOCATE (catalog[0].measureT, MeasureTiny, catalog[0].Nmeasure);
     296  ALLOCATE (catalog[0].averageT, AverageTiny, catalog[0].Naverage);
     297
     298  for (i = 0; i < catalog[0].Naverage; i++) {
     299    CopyAverageTiny (&catalog[0].averageT[i], &catalog[0].average[i]);
     300  }
     301
     302  for (i = 0; i < catalog[0].Nmeasure; i++) {
     303    CopyMeasureTiny (&catalog[0].measureT[i], &catalog[0].measure[i]);
     304  }
     305
     306  return (TRUE);
     307}
     308
     309int free_tiny_values (Catalog *catalog) {
     310
     311  free (catalog[0].averageT);
     312  free (catalog[0].measureT);
     313  return (TRUE);
     314}
     315
  • branches/czw_branch/20110406/Ohana/src/relphot/src/global_stats.c

    r5143 r31606  
    77  initstats ("MEAN");
    88
    9   stN = statsStarN (catalog, Ncatalog);
    10   stX = statsStarX (catalog, Ncatalog);
    11   stS = statsStarS (catalog, Ncatalog);
     9  fprintf (stderr, "\n");
     10  fprintf (stderr, "STATS            median     mean    sigma      min      max   Nmeas\n");
    1211
     12  int Ns;
     13  for (Ns = 0; Ns < Nphotcodes; Ns++) {
     14
     15    int thisCode = photcodes[Ns][0].code;
     16    int Nsec = GetPhotcodeNsec(thisCode);
     17    int seccode = photcodes[Ns][0].code;
     18
     19    stN = statsStarN (catalog, Ncatalog, Nsec, seccode);
     20    stX = statsStarX (catalog, Ncatalog, Nsec);
     21    stS = statsStarS (catalog, Ncatalog, Nsec);
     22 
     23    fprintf (stderr, "   --- stats for %s ---\n", photcodes[Ns][0].name);
     24    fprintf (stderr, "meas / star:    %7.0f  %7.1f  %7.1f  %7.0f  %7.0f  %6d\n",   stN.median, stN.mean, stN.sigma, stN.min, stN.max, stN.Nmeas);
     25    fprintf (stderr, "dMrel star:     %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n", stS.median, stS.mean, stS.sigma, stS.min, stS.max, stS.Nmeas);
     26    fprintf (stderr, "chisq star:     %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   stX.median, stX.mean, stX.sigma, stX.min, stX.max, stX.Nmeas);
     27  }
     28 
    1329  imN = statsImageN (catalog);
    1430  imX = statsImageX (catalog);
    1531  imM = statsImageM (catalog);
    1632  imD = statsImagedM (catalog);
    17 
     33 
    1834  msN = statsMosaicN (catalog);
    1935  msM = statsMosaicM (catalog);
    2036  msD = statsMosaicdM (catalog);
    2137  msX = statsMosaicX (catalog);
    22 
    23   fprintf (stderr, "STATS            median     mean    sigma      min      max   Nmeas\n");
     38 
    2439  fprintf (stderr, "meas / image:   %7.0f  %7.0f  %7.0f  %7.0f  %7.0f  %6d\n",   imN.median, imN.mean, imN.sigma, imN.min, imN.max, imN.Nmeas);
    25   fprintf (stderr, "meas / mosaic:  %7.0f  %7.0f  %7.0f  %7.0f  %7.0f  %6d\n",   msN.median, msN.mean, msN.sigma, msN.min, msN.max, msN.Nmeas);
    26   fprintf (stderr, "meas / star:    %7.0f  %7.1f  %7.1f  %7.0f  %7.0f  %6d\n",   stN.median, stN.mean, stN.sigma, stN.min, stN.max, stN.Nmeas);
    27 
    28   fprintf (stderr, "chisq image:    %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   imX.median, imX.mean, imX.sigma, imX.min, imX.max, imX.Nmeas);
    29   fprintf (stderr, "chisq mosaic:   %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas);
    30   fprintf (stderr, "chisq star:     %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   stX.median, stX.mean, stX.sigma, stX.min, stX.max, stX.Nmeas);
    31 
    3240  fprintf (stderr, "Mcal image:     %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   imM.median, imM.mean, imM.sigma, imM.min, imM.max, imM.Nmeas);
    3341  fprintf (stderr, "dMcal image:    %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   imD.median, imD.mean, imD.sigma, imD.min, imD.max, imD.Nmeas);
     42  fprintf (stderr, "chisq image:    %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   imX.median, imX.mean, imX.sigma, imX.min, imX.max, imX.Nmeas);
    3443
     44  fprintf (stderr, "meas / mosaic:  %7.0f  %7.0f  %7.0f  %7.0f  %7.0f  %6d\n",   msN.median, msN.mean, msN.sigma, msN.min, msN.max, msN.Nmeas);
    3545  fprintf (stderr, "Mcal mosaic:    %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   msM.median, msM.mean, msM.sigma, msM.min, msM.max, msM.Nmeas);
    3646  fprintf (stderr, "dMcal mosaic:   %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n",   msD.median, msD.mean, msD.sigma, msD.min, msD.max, msD.Nmeas);
    37 
    38   fprintf (stderr, "dMrel star:     %7.4f  %7.4f  %7.4f  %7.4f  %7.4f  %6d\n\n", stS.median, stS.mean, stS.sigma, stS.min, stS.max, stS.Nmeas);
     47  fprintf (stderr, "chisq mosaic:   %7.1f  %7.1f  %7.1f  %7.1f  %7.1f  %6d\n",   msX.median, msX.mean, msX.sigma, msX.min, msX.max, msX.Nmeas);
     48 
    3949
    4050  initstats (STATMODE);
  • branches/czw_branch/20110406/Ohana/src/relphot/src/initialize.c

    r30616 r31606  
    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);
     
    5588    exit (0);
    5689  }
     90
     91  // init the random seed
     92  long A, B;
     93  A = time(NULL);
     94  for (B = 0; A == time(NULL); B++);
     95  srand48(B);
    5796}
    58 
  • branches/czw_branch/20110406/Ohana/src/relphot/src/load_images.c

    r31160 r31606  
    4444  // select the images which overlap the selected sky regions
    4545  subset = select_images (skylist, image, Nimage, &LineNumber, &Nsubset);
    46   MARKTIME("selected images: %f sec\n", dtime);
     46  MARKTIME("selected %d overlapping images: %f sec\n", (int) Nsubset, dtime);
    4747
    4848  // generate db->vtable from db->ftable based on the selection
  • branches/czw_branch/20110406/Ohana/src/relphot/src/plot_scatter.c

    r27435 r31606  
    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].secfilt[Nsecfilt*j+Nsec].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].measureT[m].photcode);
     39                if (ecode != thisCode) { continue; }
     40
     41                if (catalog[i].measureT[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] = PhotSysTiny (&catalog[i].measureT[m], &catalog[i].averageT[j], &catalog[i].secfilt[j*Nsecfilt]) - Mcal - Mmos - Mgrid - Mrel;
     52                ilist[N] = PhotInstTiny (&catalog[i].measureT[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/czw_branch/20110406/Ohana/src/relphot/src/reload_catalogs.c

    r15743 r31606  
    11# include "relphot.h"
     2
     3# define TIMESTAMP(TIME) \
     4    gettimeofday (&stop, (void *) NULL);        \
     5    dtime = DTIME (stop, start);                \
     6    TIME += dtime;                              \
     7    gettimeofday (&start, (void *) NULL);
    28
    39void reload_catalogs (SkyList *skylist) {
     
    814  Catalog catalog;
    915
     16  struct timeval start, stop;
     17  double dtime = 0.0;
     18  double time1 = 0.0;
     19  double time2 = 0.0;
     20  double time3 = 0.0;
     21  double time4 = 0.0;
     22  double time5 = 0.0;
     23  double time6 = 0.0;
     24  double time7 = 0.0;
     25
    1026  if (VERBOSE) fprintf (stderr, "re-loading catalog data\n");
    1127
    1228  /* load data from each region file */
    1329  for (i = 0; i < skylist[0].Nregions; i++) {
     30    gettimeofday (&start, (void *) NULL);
    1431    catalog.filename = skylist[0].filename[i];
    1532
     
    2037      continue;
    2138    }
     39    TIMESTAMP(time1);
    2240
    2341    catalog.catformat = dvo_catalog_catformat (CATFORMAT);    // set the default catformat from config data
     
    3654        continue;
    3755    }
     56    TIMESTAMP(time2);
     57
     58    populate_tiny_values(&catalog);
    3859
    3960    initImageBins  (&catalog, 1);
    4061    initMosaicBins (&catalog, 1);
    41     initGridBins   (&catalog, 1);
     62    initGridBins   (&catalog, 1);
     63    TIMESTAMP(time3);
    4264
    43     findImages (&catalog, 1);
    44     findMosaics (&catalog, 1);
     65    findImages (&catalog, 1);  // FX
     66    findMosaics (&catalog, 1); //
     67    TIMESTAMP(time4);
    4568
    4669    setMrelFinal (&catalog);
     70    TIMESTAMP(time5);
     71
    4772    dvo_catalog_save (&catalog, VERBOSE);
    4873    dvo_catalog_unlock (&catalog);
     74
     75    free_tiny_values(&catalog);
    4976    dvo_catalog_free (&catalog);
     77    TIMESTAMP(time6);
    5078
    5179    freeImageBins (1);
    5280    freeMosaicBins (1);
    5381    freeGridBins (1);
     82    TIMESTAMP(time7);
    5483  }
     84
     85  fprintf (stderr, "time1 %f : find catalog\n", time1);
     86  fprintf (stderr, "time2 %f : load catalog\n", time2);
     87  fprintf (stderr, "time3 %f : init imbins\n",  time3);
     88  fprintf (stderr, "time4 %f : find images\n",  time4);
     89  fprintf (stderr, "time5 %f : set Mrel\n",     time5);
     90  fprintf (stderr, "time6 %f : save catalog\n", time6);
     91  fprintf (stderr, "time7 %f : free catalog\n", time7);
    5592}
  • branches/czw_branch/20110406/Ohana/src/relphot/src/relphot.c

    r30616 r31606  
    4747    if (!dvo_image_load (&db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
    4848  }
    49   MARKTIME("load image data: %f sec\n", dtime);
     49  MARKTIME("-- load image data: %f sec\n", dtime);
    5050
    5151  /* load regions and images based on specified sky patch */
     
    5454  // XXX this is fairly lame: argv[1] is photcode if UserPatchSelect is true
    5555  skylist = load_images (&db, argv[1], &UserPatch, UserPatchSelect);
    56   MARKTIME("load images: %f sec\n", dtime);
     56  MARKTIME("-- load images: %f sec\n", dtime);
    5757
    5858  /* unlock, if we can (else, unlocked below) */
     
    6161  /* load catalog data from region files */
    6262  catalog = load_catalogs (skylist, &Ncatalog);
    63   MARKTIME("load catalog data: %f sec\n", dtime);
     63  MARKTIME("-- load catalog data: %f sec\n", dtime);
    6464 
    6565  /* add in a loop over the catalogs calling dvo_catalog_chipcoords */
     
    6767  /* match measurements with images, mosaics */
    6868  initImageBins  (catalog, Ncatalog);
    69   MARKTIME("make image bins: %f sec\n", dtime);
     69  MARKTIME("-- make image bins: %f sec\n", dtime);
    7070
    7171  initMosaicBins (catalog, Ncatalog);
     
    7474
    7575  findImages (catalog, Ncatalog);
    76   MARKTIME("set up image indexes: %f sec\n", dtime);
     76  MARKTIME("-- set up image indexes: %f sec\n", dtime);
    7777
    7878  findMosaics (catalog, Ncatalog);  /* also sets Grid values */
    79   MARKTIME("set up mosaic indexes: %f sec\n", dtime);
     79  MARKTIME("-- set up mosaic indexes: %f sec\n", dtime);
    8080
    8181  SAVEPLOT = FALSE;
    8282
    8383  setExclusions (catalog, Ncatalog);
     84
     85  global_stats (catalog, Ncatalog);
    8486
    8587  if (PLOTSTUFF) {
     
    9193  if (USE_GRID) {
    9294      int star_toofew;
    93 
    94 # if (USE_DIRECT)
    95       // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW
    96       // XXX this is kind of poor: need to have a better distinctions about STAR_BAD in setMrel vs getMrel
    97       star_toofew = STAR_TOOFEW;
    98       STAR_TOOFEW = 0;
    99       STAR_BAD  = ID_STAR_POOR;
    100 
    101       showGridCount ();
    102       setMgridDirect (catalog, Ncatalog);
    103 
    104       STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
    105       STAR_TOOFEW = star_toofew;
    106 
    107       dump_grid ();
    108       exit (0);
    109 
    110 # else
    11195
    11296      // until we finish the grid analysis, do not reject stars out-of-hand based on ID_STAR_FEW
     
    122106      STAR_BAD  = ID_STAR_POOR | ID_STAR_FEW;
    123107      STAR_TOOFEW = star_toofew;
    124 # endif
    125108  }
    126109
     
    140123      plot_chisq (catalog, Ncatalog);
    141124    }
    142     if ((i == 1) || (i == 5) || (i ==  9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE);
    143     if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog);
    144     if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics ();
    145     if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images ();
     125    if (i % 6 == 1) rationalize_mosaics (catalog, Ncatalog);
     126    // if (i % 6 == 1) rationalize_images ();
     127    if (i % 6 == 2) clean_measures (catalog, Ncatalog, FALSE);
     128    if (i % 6 == 3) clean_stars (catalog, Ncatalog);
     129    if (i % 6 == 5) clean_mosaics ();
     130    if (i % 6 == 5) clean_images ();
     131
     132    // if ((i == 1) || (i == 5) || (i ==  9) || (i == 13)) clean_measures (catalog, Ncatalog, FALSE);
     133    // if ((i == 2) || (i == 6) || (i == 10) || (i == 14)) clean_stars (catalog, Ncatalog);
     134    // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_mosaics ();
     135    // if ((i == 4) || (i == 8) || (i == 12) || (i == 16)) clean_images ();
    146136    global_stats (catalog, Ncatalog);
     137    MARKTIME("-- finished loop %d: %f sec\n", i, dtime);
    147138  }
    148139
    149   SAVEPLOT = TRUE;
    150   plot_scatter (catalog, Ncatalog);
    151   plot_grid (catalog);
    152   plot_mosaics ();
    153   plot_images ();
    154   plot_stars (catalog, Ncatalog);
    155   plot_chisq (catalog, Ncatalog);
    156 
     140  if (PLOTSTUFF) {
     141    plot_scatter (catalog, Ncatalog);
     142    plot_grid (catalog);
     143    plot_mosaics ();
     144    plot_images ();
     145    plot_stars (catalog, Ncatalog);
     146    plot_chisq (catalog, Ncatalog);
     147  }
     148 
    157149  if (USE_GRID) dump_grid ();
    158150  if (!UPDATE) exit (0);
     
    161153  setMcal  (catalog, TRUE);
    162154  setMmos  (catalog, TRUE);
     155  MARKTIME("-- finalize Mcal values: %f sec\n", dtime);
    163156
    164157  /* at this point, we have correct cal coeffs in the image/mosaic structures */
    165   for (i = 0; i < Ncatalog; i++) dvo_catalog_free (&catalog[i]);
     158  for (i = 0; i < Ncatalog; i++) {
     159    free_tiny_values (&catalog[i]);
     160    dvo_catalog_free (&catalog[i]);
     161  }
    166162  freeImageBins (Ncatalog);
    167163  freeMosaicBins (Ncatalog);
     
    170166  /* load catalog data from region files, update Mrel include all data */
    171167  reload_catalogs (skylist);
     168  MARKTIME("-- updated all catalogs: %f sec\n", dtime);
     169
    172170  setMcalFinal ();
    173 
    174171  reload_images (&db);
    175172 
  • branches/czw_branch/20110406/Ohana/src/relphot/src/relphot_objects.c

    r28241 r31606  
    33int relphot_objects () {
    44
    5   off_t i, j, k, m;
     5  off_t i, j, k;
    66  int Nsecfilt;
    77
     
    3838    }
    3939
    40     // XXX consider what gets reset (only PHOTOM flags)
     40    // reset
    4141    if (RESET) {
    4242      Nsecfilt = catalog.Nsecfilt;
     
    5151          catalog.secfilt[j*Nsecfilt + k].Ncode = 0;
    5252          catalog.secfilt[j*Nsecfilt + k].Nused = 0;
    53         }
    54         m = catalog.average[j].measureOffset;
    55         for (k = 0; k < catalog.average[j].Nmeasure; k++) {
    56           catalog.measure[m+k].dbFlags = 0;
    57           catalog.measure[m+k].Mcal = 0;
     53          // XXX reset the photometry flags for secfilt entries?
    5854        }
    5955      }
  • branches/czw_branch/20110406/Ohana/src/relphot/src/select_images.c

    r31160 r31606  
    6464  DmaxSkyRegion = -90.0;
    6565
     66  // FILE *ftest = fopen ("relphot.dump.dat", "w");
     67
    6668  /* compare with each region file */
    6769  for (i = 0; i < skylist[0].Nregions; i++) {
     
    117119    /* exclude images by photcode */
    118120    ecode = GetPhotcodeEquivCodebyCode (timage[i].photcode);
    119     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;
    120127
    121128    /* exclude images by time */
     
    130137      continue;
    131138    }
     139
     140    // XXX temporary test : record center coords for each accepted and rejected chip/mosaic
     141    // double RAo, DECo;
    132142
    133143    /* define image corners - note the DIS images (mosaic phu) are special */
     
    138148      Xi[3] = -0.5*timage[i].NX; Yi[3] = +0.5*timage[i].NY;
    139149      Xi[4] = -0.5*timage[i].NX; Yi[4] = -0.5*timage[i].NY;
     150      // XY_to_RD(&RAo, &DECo, 0.0, 0.0, &timage[i].coords);
    140151    } else {
    141152      Xi[0] = 0;            Yi[0] = 0;
     
    144155      Xi[3] = 0;            Yi[3] = timage[i].NY;
    145156      Xi[4] = 0;            Yi[4] = 0;
     157      // XY_to_RD(&RAo, &DECo, 0.5*timage[i].NX, 0.5*timage[i].NY, &timage[i].coords);
    146158    }
    147159    found = FALSE;
    148160
    149161    /* transform corners to ra,dec -- costs ~3sec for 3M images (pikake) */
    150     double RminImage = 360.0;
    151     double RmaxImage =   0.0;
     162    double RminImage = RmidSkyRegion + 180.0;
     163    double RmaxImage = RmidSkyRegion - 180.0;
    152164    double DminImage = +90.0;
    153165    double DmaxImage = -90.0;
     
    218230
    219231  found_it:
     232    // XXX We claim this is a good image: write to a test file
     233    // fprintf (ftest, "%s : %lf %lf  : %f %f %d %x\n", timage[i].name, RAo, DECo, timage[i].Mcal, timage[i].dMcal, timage[i].nstar, timage[i].flags);
     234
    220235    image[nimage] = timage[i];
    221236    /* always allow 'few' images to succeed, if possible */
     
    239254  }
    240255  MARKTIME("finish image selection: %f sec\n", dtime);
     256
     257  // fclose (ftest);
    241258
    242259  if (VERBOSE) fprintf (stderr, "found "OFF_T_FMT" images\n", nimage);
  • branches/czw_branch/20110406/Ohana/src/relphot/src/setExclusions.c

    r28241 r31606  
    11# include "relphot.h"
     2
     3// this function sets the NOCAL and AREA dbFlags bits for the MeasureTiny elements these
     4// are used elsewhere (StarOps.c, ImageOps.c, MosaicOps.c, GridOps.c, etc) to skip bad
     5// measurements.  The only exception is 'setMave' which is called by 'relphot_objects',
     6// and uses the bits read from disk as the test
    27
    38int setExclusions (Catalog *catalog, int Ncatalog) {
    49
    510  off_t i, j, k, m, Narea, Nnocal, Ngood;
    6   int ecode;
     11  int ecode, found, Ns;
    712  Coords *coords;
    813  double r, d, x, y;
     
    1116  for (i = 0; i < Ncatalog; i++) {
    1217    for (j = 0; j < catalog[i].Naverage; j++) {
    13       m = catalog[i].average[j].measureOffset;
    14       for (k = 0; k < catalog[i].average[j].Nmeasure; k++, m++) {
     18      m = catalog[i].averageT[j].measureOffset;
     19      for (k = 0; k < catalog[i].averageT[j].Nmeasure; k++, m++) {
    1520
    1621        /* select measurements by photcode */
    17         ecode = GetPhotcodeEquivCodebyCode (catalog[i].measure[m].photcode);
    18         if (ecode != photcode[0].code) goto mark_nocal;
     22        ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[m].photcode);
     23        found = FALSE;
     24        for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     25            if (ecode == photcodes[Ns][0].code) found = TRUE;
     26        }
     27        if (!found) goto mark_nocal;
    1928       
    2029        /* select measurements by time */
    2130        if (TimeSelect) {
    22           if (catalog[i].measure[m].t < TSTART) goto mark_nocal;
    23           if (catalog[i].measure[m].t > TSTOP) goto mark_nocal;
     31          if (catalog[i].measureT[m].t < TSTART) goto mark_nocal;
     32          if (catalog[i].measureT[m].t > TSTOP) goto mark_nocal;
    2433        }
    2534
    2635        /* select measurements by mag limit */
    2736        if (AreaSelect) {
    28           r = catalog[i].average[j].R + catalog[i].measure[m].dR / 3600.0;
    29           d = catalog[i].average[j].D + catalog[i].measure[m].dD / 3600.0;
     37          r = catalog[i].averageT[j].R + catalog[i].measureT[m].dR / 3600.0;
     38          d = catalog[i].averageT[j].D + catalog[i].measureT[m].dD / 3600.0;
    3039          if ((coords = getCoords (m, i)) == NULL) goto markbad;
    3140          RD_to_XY (&x, &y, r, d, coords);
     
    3948
    4049      markbad:
    41         catalog[i].measure[m].dbFlags |= ID_MEAS_AREA;
     50        catalog[i].measureT[m].dbFlags |= ID_MEAS_AREA;
    4251        Narea ++;
    4352        continue;
    4453       
    4554      mark_nocal:
    46         catalog[i].measure[m].dbFlags |= ID_MEAS_NOCAL;
     55        catalog[i].measureT[m].dbFlags |= ID_MEAS_NOCAL;
    4756        Nnocal ++;
    4857        continue;
  • branches/czw_branch/20110406/Ohana/src/relphot/src/setMrelFinal.c

    r29001 r31606  
    11# include "relphot.h"
     2
     3// we've just reloaded the data from disk; we now need to apply the Image/Mosaic/Grid
     4// calibrations determined by the rest of the program.  We also need to set the final
     5// output dbFlags values
    26
    37void setMrelFinal (Catalog *catalog) {
     
    913  if (RESET) {
    1014
    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;
     15    int Nsecfilt = GetPhotcodeNsecfilt ();
    1516
    16       m = catalog[0].average[i].measureOffset;
    17       for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
     17    int Ns;
     18    for (Ns = 0; Ns < Nphotcodes; Ns++) {
    1819       
    19         /* select measurements by photcode */
    20         ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
    21         if (ecode != photcode[0].code) continue;
     20      int thisCode = photcodes[Ns][0].code;
     21      int Nsec = GetPhotcodeNsec(thisCode);
     22
     23      for (i = 0; i < catalog[0].Naverage; i++) {
     24        catalog[0].secfilt[Nsecfilt*i+Nsec].M  = NAN;
     25        catalog[0].secfilt[Nsecfilt*i+Nsec].dM = NAN;
     26        catalog[0].secfilt[Nsecfilt*i+Nsec].Xm = NAN_S_SHORT;
     27
     28        m = catalog[0].average[i].measureOffset;
     29        for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
    2230       
    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;
     31          // skip measurements that do not match the current photcode
     32          ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
     33          if (ecode != thisCode) { continue; }
     34
     35          /* select measurements by time */
     36          if (TimeSelect) {
     37            if (catalog[0].measure[m].t < TSTART) continue;
     38            if (catalog[0].measure[m].t > TSTOP) continue;
     39          }
     40       
     41          catalog[0].measure[m].Mcal = 0;
     42          catalog[0].measure[m].dbFlags &= 0xff00;
     43          catalog[0].measure[m].dbFlags &= ~ID_MEAS_POOR_PHOTOM;
     44          catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
     45          catalog[0].measure[m].dbFlags &= ~ID_MEAS_AREA;
     46          catalog[0].measure[m].dbFlags &= ~ID_MEAS_NOCAL;
    2747        }
    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;
    3548      }
    3649    }
    3750  }
    3851
     52  // this sets flags in the measureT element, not the measure element
    3953  setExclusions (catalog, 1);  /* mark by area */
    4054
     
    5367  setMcalOutput (catalog, 1);
    5468
    55   /* clear ID_STAR_POOR, ID_STAR_FEW, ID_MEAS_NOCAL values before writing ??? */
     69  int Nsecfilt = GetPhotcodeNsecfilt ();
     70
     71  /* clear ID_STAR_POOR, ID_STAR_FEW values before writing ??? */
     72  /* ID_MEAS_NOCAL is an internal bit, so it should be cleared */
    5673  for (i = 0; i < catalog[0].Naverage; i++) {
    5774    catalog[0].average[i].flags &= ~ID_STAR_FEW;
    5875    catalog[0].average[i].flags &= ~ID_STAR_POOR;
     76    for (j = 0; j < Nsecfilt; j++) {
     77        catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_STAR_FEW;
     78        catalog[0].secfilt[i*Nsecfilt+j].flags &= ~ID_STAR_POOR;
     79    }
    5980    m = catalog[0].average[i].measureOffset;
    6081    for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
     
    6889
    6990  off_t i, k, m;
    70   int ecode;
     91  int ecode, found, Ns;
    7192  off_t Ntot, Ntry, Nkeep, Nskip;
    7293  float mag;
     
    90111
    91112      /* clear SKIP for all measures at first */
    92       catalog[0].measure[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
     113      catalog[0].measureT[m].dbFlags &= ~ID_MEAS_SKIP_PHOTOM;
    93114
    94115      /** never use these measurements (wrong photcode, bad time range) */
    95116      /* skipped via NOCAL, don't mark as skipped */
    96117      ecode = GetPhotcodeEquivCodebyCode (catalog[0].measure[m].photcode);
    97       if (ecode != photcode[0].code) continue;
     118      found = FALSE;
     119      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     120        if (ecode == photcodes[Ns][0].code) found = TRUE;
     121      }
     122      if (!found) continue;
    98123
    99124      /* skip measurements by time range */
     
    134159
    135160    skip:
    136       catalog[0].measure[m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
     161      catalog[0].measure [m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
     162      catalog[0].measureT[m].dbFlags |= ID_MEAS_SKIP_PHOTOM;
    137163      Nskip ++;
    138164    }
  • branches/czw_branch/20110406/Ohana/src/skycalc/Makefile

    r30609 r31606  
    7575
    7676%.install:
    77         make $(DESTBIN)/$*
     77        $(MAKE) $(DESTBIN)/$*
    7878
    7979install:
    80         for i in $(INSTALL); do make $$i.install || exit; done
     80        for i in $(INSTALL); do $(MAKE) $$i.install || exit; done
  • branches/czw_branch/20110406/Ohana/src/tools/Makefile

    r29938 r31606  
    5757
    5858%.install:
    59         make $(DESTBIN)/$*
     59        $(MAKE) $(DESTBIN)/$*
    6060
    6161install:
    62         for i in $(PROGRAMS); do make $$i.install || exit; done
     62        for i in $(PROGRAMS); do $(MAKE) $$i.install || exit; done
    6363
    6464
  • branches/czw_branch/20110406/dbconfig/changes.txt

    • Property svn:mergeinfo deleted
    r31434 r31606  
    21322132UPDATE dbversion set schema_version = '1.1.70', updated= CURRENT_TIMESTAMP();
    21332133
     2134-- heather discovered that we need keys for addRun:
     2135
     2136alter table addRun add key(stage), add key (stage_id);
  • branches/czw_branch/20110406/ippScripts/scripts/camera_exp.pl

    r30071 r31606  
    153153    }
    154154    chomp $cmdflags;
     155
     156    { # Determine if FWHM is too large to bother continuing.
     157        my $command = "$ppConfigDump -camera $camera -dump-camera -";
     158        my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     159            run(command => $command, verbose => $verbose);
     160        unless ($success) {
     161            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     162            &my_die("Unable to perform ppConfigDump: $error_code", $cam_id, $PS_EXIT_CONFIG_ERROR);
     163        }
     164        my $cameraConfig = $mdcParser->parse(join "", @$stdout_buf) or
     165            &my_die("Unable to parse metadata config doc", $cam_id, $PS_EXIT_CONFIG_ERROR);
     166
     167        my $maxFWHM = metadataLookupStr($cameraConfig, 'MAX_ALLOWED_FWHM');
     168        if ($maxFWHM) {
     169            my $expFWHM;
     170            ($expFWHM) = $cmdflags =~ /-fwhm_major (\d+)/;     
     171           
     172            if ($expFWHM > $maxFWHM) {
     173                print "Setting quality to 4007 due to large FWHM: exposure: $expFWHM  maximum: $maxFWHM\n";
     174                $cmdflags .= " -quality 4007 "; # This corresponds to PSASTRO_ERR_DATA
     175                $no_op = 1;
     176            }
     177        }
     178    }
    155179}
    156180
  • branches/czw_branch/20110406/ippScripts/scripts/dist_advancerun.pl

    r30489 r31606  
    114114    $tool_cmd = "$staticskytool -sky_id";
    115115    $list_mode = "-result";
    116     $component_key = "";
     116    $component_key = "skycell_id";
    117117} elsif ($stage eq "diff") {
    118118    $tool_cmd = "$difftool -diff_id";
  • branches/czw_branch/20110406/ippScripts/scripts/dist_bundle.pl

    r30922 r31606  
    6262my $streaksrelease   = can_run('streaksrelease') or (warn "Can't find streaksrelease" and $missing_tools = 1);
    6363my $bgtool   = can_run('bgtool') or (warn "Can't find bgtool" and $missing_tools = 1);
     64my $staticskytool   = can_run('staticskytool') or (warn "Can't find staticskytool" and $missing_tools = 1);
    6465my $file_cmd   = can_run('file') or (warn "can't find program file" and $missing_tools = 1);
    6566my $zcat   = can_run('zcat') or (warn "can't find program zcat" and $missing_tools = 1);
     
    106107    defined $stage_id and
    107108    defined $component and
    108     defined $exp_type and
    109109    defined $path_base and
    110110    defined $outroot;
    111111
     112if ($stage eq 'raw' and !$clean and !$no_magic) {
     113   
     114    # for raw stage need to have exposure type defined and if the type is OBJECT we need
     115    # a chip_path_base so we can find the chip mask file
     116    if (!defined $exp_type or ($exp_type eq 'OBJECT' and !defined $chip_path_base)) {
     117        pod2usage( -msg => "Required options: --chip_path_base --exp_type for raw stage", -exitval => 3);
     118    }
     119}
     120
    112121$ipprc->redirect_output($logfile) if $logfile;
    113122
    114 if ($stage eq 'raw' and !$clean and !$no_magic) {
    115     # need to be able to find chip mask file
    116     if ($exp_type eq 'OBJECT' and !defined $chip_path_base) {
    117         pod2usage( -msg => "Required options: --chip_path_base for raw stage", -exitval => 3);
    118     }
    119 }
    120 
    121123$ipprc->define_camera($camera);
    122124
    123125$ipprc->outroot_prepare($outroot);
    124126
     127my $num_sky_inputs;
     128if ($stage eq 'sky') {
     129    $num_sky_inputs = get_num_sky_inputs($stage_id);
     130}
    125131# Get the list of data products for this component
    126132# note: We my_die in get_file_list if something goes wrong.
    127133
    128 my $file_list = get_file_list($stage, $component, $path_base, $clean);
     134my $file_list = get_file_list($stage, $component, $path_base, $clean, $num_sky_inputs);
    129135
    130136if (($stage ne 'raw') and ($stage ne 'fake') and !$poor_quality) {
     
    184190        # it must exist)
    185191        next if $poor_quality;
     192
     193        # skip file stats file. Due to a bug the update process destroys them sometimes
     194        # XXX: perhaps only do this for stages where we know that this happens
     195        next if $file_rule =~ /STATS/;
    186196
    187197        &my_die("failed to resolve  $file_name", $component, $PS_EXIT_DATA_ERROR);
     
    480490    my $path_base = shift;
    481491    my $clean = shift;
     492    my $num_sky_inputs = shift;
    482493
    483494    my @file_list;
     
    531542        $config_file_rule = "PPSTACK.CONFIG";
    532543    } elsif ($stage eq "sky") {
    533         $config_file_rule = "PSPHOT.STACK.CONFIG";
     544        if ($num_sky_inputs > 1) {
     545            $config_file_rule = "PSPHOT.STACK.CONFIG";
     546        } else {
     547            $config_file_rule = "PSPHOT.SKY.CONFIG";
     548        }
    534549    } else {
    535550        &my_die("$stage is not a valid stage", $component, $PS_EXIT_CONFIG_ERROR);
     
    627642    return \@file_list;
    628643}
     644sub get_num_sky_inputs {
     645    my $sky_id = shift;
     646
     647    my $command = "$staticskytool -inputs -sky_id $sky_id -simple";
     648    $command .= " -dbname $dbname" if $dbname;
     649    $command .= " | wc";
     650    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     651        run(command => $command, verbose => $verbose);
     652    unless ($success) {
     653        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     654        &my_die("Unable to perform $command: $error_code", $component, $error_code);
     655    }
     656    my ($num_inputs, $words, $chars) = split " ", (join "", @$stdout_buf);
     657    if (!$num_inputs) {
     658        $num_inputs = "undefined" if !defined $num_inputs;
     659        &my_die("unexpected number of static sky inputs $num_inputs",  $PS_EXIT_PROG_ERROR, $component, $error_code);
     660    }
     661
     662    return $num_inputs;
     663}
    629664
    630665sub my_die
  • branches/czw_branch/20110406/ippScripts/scripts/ipp_apply_burntool_single.pl

  • branches/czw_branch/20110406/ippScripts/scripts/magic_destreak.pl

    r31432 r31606  
    364364        }
    365365        else {
    366             print "Did not add sources because the do not appear to exist. This may be an error.\n";
     366            print "Did not add sources because they do not appear to exist. This may be an error.\n";
    367367        }
    368368        $command .= " -skycelllist $skycell_list" if defined $skycell_list;
  • branches/czw_branch/20110406/ippScripts/scripts/receive_file.pl

    r30674 r31606  
    224224        $stage = 'sky';
    225225        # XXX: This should be skycell, but the distribution code uses exposure
    226         $comp_name = 'exposure';
    227         $current_component = $comp_name;
     226        $comp_name = 'skycell_id';
     227#        $current_component = $comp_name;
    228228    } else {
    229229        &my_die( "unexpected run type line found in $filename: $runType\n", $file_id, $PS_EXIT_UNKNOWN_ERROR);
     
    237237        $new_workdir_value = "$workdir/$destdir";
    238238    }
     239
     240    if ($stage eq 'sky') {
     241        # the dbinfo file for a skyRun only has one component and it doesn't contain
     242        # skycell_id which is the way components are listed in the dirinfo file.
     243        my @ids = keys %$components;
     244        &my_die( "unexpected number of components scalar @ids found in staticsky dirinfo file\n", $file_id, $PS_EXIT_UNKNOWN_ERROR) if scalar @ids != 1;
     245        $current_component = $ids[0];
     246    }
     247
    239248    my $component_dir;
    240249    if ($current_component) {
  • branches/czw_branch/20110406/ippScripts/scripts/register_imfile.pl

    r31060 r31606  
    4040
    4141my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $bytes, $md5sum, $dbname, $verbose, $no_update, $no_op, $logfile);
    42 my ($sunrise, $sunset);
     42my ($sunrise, $sunset, $summit_dateobs);
    4343GetOptions(
    4444    'caches'           => \$cache,
     
    5151    'sunrise=s'        => \$sunrise,
    5252    'sunset=s'         => \$sunset,
     53    'summit_dateobs=s' => \$summit_dateobs,
    5354    'dbname|d=s'       => \$dbname,    # Database name
    5455    'verbose'          => \$verbose,   # Print to stdout
     
    181182if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die_for_add ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    182183my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
     184unless($summit_dateobs) {
     185    $summit_dateobs = $dateobs;
     186}
     187
    183188my $exp_type  = &value_for_flag($cmdflags, "NULL", "-exp_type");
    184189
     
    196201    $command .= " -data_state full";
    197202}
    198 elsif (is_daytime($dateobs,$sunrise,$sunset)) {
     203elsif (is_daytime($summit_dateobs,$sunrise,$sunset)) {
    199204    printf STDERR "This is a daytime exposure.\n";
    200205    $command .= " -data_state full";
     
    267272
    268273if ((abs($burntoolStateCurrent) != $burntoolStateTarget)&&
    269     (!is_daytime($dateobs,$sunrise,$sunset))&&
     274    (!is_daytime($summit_dateobs,$sunrise,$sunset))&&
    270275    (!is_ccim($tmp_exp_name,$exp_type))) {
    271276    my $mdcParser  = PS::IPP::Metadata::Config->new;
  • branches/czw_branch/20110406/ippScripts/scripts/warp_skycell.pl

    r30825 r31606  
    7272
    7373my ($logDest, $traceDest);
     74my $do_stats;
    7475if ($run_state eq 'new') {
    7576    $logDest = prepare_output("LOG.EXP", $outroot, $skycell_id, 0);
    7677    $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1);
     78    $do_stats = 1;
    7779} elsif ($run_state eq 'update')  {
    7880    $logDest = prepare_output("LOG.EXP.UPDATE", $outroot, $skycell_id, 1);
     
    162164my $outputBin1 = prepare_output ("PSWARP.BIN1", $outroot, $skycell_id, 1);
    163165my $outputBin2 = prepare_output ("PSWARP.BIN2", $outroot, $skycell_id, 1);
    164 my $outputStats = prepare_output ("SKYCELL.STATS", $outroot, $skycell_id, 1);
     166my $outputStats;
     167if ($do_stats) {
     168    $outputStats = prepare_output ("SKYCELL.STATS", $outroot, $skycell_id, 1) if $do_stats;
     169}
    165170my $configuration;
    166171
     
    257262# Run pswarp
    258263my $cmdflags;
    259 my $do_stats;
    260264unless ($no_op) {
    261265    my $command = "$pswarp";
     
    279283    if ($run_state eq 'new') {
    280284        $command .= " -dumpconfig $configuration";
    281         $do_stats = 1;
    282285    } else {
    283286        $command .= " -ipprc $configuration";
  • branches/czw_branch/20110406/ippTasks/Makefile.am

    r30375 r31606  
    4141        lossy_compress.pro \
    4242        background.pro \
    43         diffphot.pro
     43        diffphot.pro \
     44        lap.pro
    4445
    4546other_files = \
  • branches/czw_branch/20110406/ippTasks/register.pro

    r30992 r31606  
    294294    book getword regPendingImfile $pageName workdir      -var WORKDIR_TEMPLATE
    295295    book getword regPendingImfile $pageName dbname       -var DBNAME
     296    book getword regPendingImfile $pageName summit_dateobs -var SUMMIT_DATEOBS
    296297
    297298    # EXP_TAG is used to generate the unique, but human-readable, filenames
     
    320321    # XXX register_imfile.pl differs from the standard script : it does not have an 'outroot' argument, and it does not take '--redirect'
    321322    $run = register_imfile.pl --exp_id $EXP_ID --tmp_class_id $TMP_CLASS_ID --tmp_exp_name $TMP_EXP_NAME --uri $URI --logfile $logfile --bytes $BYTES --md5sum $MD5SUM
    322     $run = $run --sunset $sunset --sunrise $sunrise
     323    $run = $run --sunset $sunset --sunrise $sunrise --summit_dateobs $SUMMIT_DATEOBS
    323324    add_standard_args run
    324325
  • branches/czw_branch/20110406/ippToPsps/jython/batch.py

    r31434 r31606  
    3232    "../config/2/tables.vot"
    3333    '''
    34     def __init__(self, logger, batchType, inputFitsPath="", survey="", useFullTables=False):
     34    def __init__(self,
     35                 logger,
     36                 gpc1Db,
     37                 ippToPspsDb,
     38                 scratchDb,
     39                 id,
     40                 batchType,
     41                 inputFitsPath="",
     42                 survey="",
     43                 useFullTables=False):
     44
     45        self.everythingOK = False
     46        self.readHeader = False
    3547
    3648        # set up logging
     
    4052
    4153        # set up class variables
     54        self.id = id
     55        self.gpc1Db = gpc1Db
     56        self.ippToPspsDb = ippToPspsDb
     57        self.scratchDb = scratchDb
    4258        self.batchType = batchType;
    4359        self.pspsVoTableFilePath = "../config/" + batchType + "/tables.vot"
     
    4662        self.useFullTables = useFullTables
    4763
     64        if self.alreadyProcessed(): return
     65
     66        # do we have an input file?
     67        if self.inputFitsPath != "":
     68
     69            if not self.readPrimaryHeader(): return
     70
    4871        # TODO
    4972        self.tablesToExport = []
     
    5174        # open config
    5275        doc = ElementTree(file="config.xml")
    53 
    54         # create Gpc1Db object
    55         self.gpc1Db = Gpc1Db(self.logger)
    56         self.ippToPspsDb = IppToPspsDb(logger)
    57         self.scratchDb = ScratchDb(logger, self.useFullTables)
    5876
    5977        if self.survey != "":
     
    88106        self.dateStr = now.strftime("%Y-%m-%d")
    89107
    90         if self.inputFitsPath != "":
    91             file = open(self.inputFitsPath)
    92             self.header = self.parseFitsHeader(file)
    93             self.logger.info("Read primary and found " + str(len(self.header)) + " header cards")
    94             # TODO close file?
    95 
    96108        # create DVO tables if accessing DVO directly
    97109        if not self.useFullTables: self.scratchDb.createDvoTables()
    98110
     111        self.everythingOK = True
     112
    99113    '''
    100114    Destructor
     
    103117
    104118        self.logger.debug("Batch destructor")
     119
     120
     121    '''
     122    Reads the primary header of the FITS file
     123    '''
     124    def readPrimaryHeader(self):
     125
     126        if self.readHeader: return True
     127
     128        # does it exist?
     129        if not os.path.isfile(self.inputFitsPath):
     130
     131            self.logger.error("Cannot read file at '" + self.inputFitsPath + "'")
     132            return False
     133
     134        file = open(self.inputFitsPath)
     135        self.header = self.parseFitsHeader(file)
     136        self.logger.info("Read primary header and found " + str(len(self.header)) + " header cards")
     137        # TODO close file?
     138
     139        self.readHeader = True
     140
     141        return True
    105142
    106143
     
    138175            file.seek(index + 2880, 0)
    139176           
    140         if found != True: self.logger.error("...could not find extension '" + name + "'")
    141         else: self.logger.info("...read header at '" + name + "' and found " + str(len(header)) + " header cards")
     177        if found != True:
     178            self.logger.error("...could not read header in extension '" + name + "'")
     179            return
     180        #else: self.logger.info("...read header at '" + name + "' and found " + str(len(header)) + " header cards")
    142181
    143182        return header
     
    262301
    263302        first = True
     303
     304        self.totalDetections = 0
    264305        for table in tables:
    265306
    266             sql = "SELECT MIN(objID), MAX(objID) FROM " + table
    267             rs = self.scratchDb.stmt.executeQuery(sql)
     307            sql = "SELECT MIN(objID), MAX(objID), COUNT(objID) FROM " + table
     308            rs = self.scratchDb.executeQuery(sql)
    268309            rs.first()
     310
     311            self.totalDetections = self.totalDetections + rs.getLong(3)
    269312
    270313            if first:
     
    276319
    277320            first = False
     321            rs.close()
    278322
    279323        self.ippToPspsDb.updateMinMaxObjID(self.batchID, self.minObjID, self.maxObjID)
     324        self.logger.info("Total detections = %ld min objID = %ld max objID = %ld" % (self.totalDetections, self.minObjID, self.maxObjID))
     325
    280326
    281327    '''
     
    313359         self.pspsTables = stilts.treads(self.pspsVoTableFilePath)
    314360         for table in self.pspsTables:
    315              self.logger.info("Creating PSPS table: " + table.name)
     361             self.logger.debug("Creating PSPS table: " + table.name)
    316362             table.write(self.scratchDb.url + '#' + table.name)
    317363             self.tablesToExport.append(table.name)
     
    337383    Accepts a regular expression filter so not all tables need to be imported
    338384    '''
    339     def importIppTables(self, filter):
     385    def importIppTables(self, filter=""):
    340386
    341387      self.logger.info("Attempting to import tables from input FITS file")
     
    347393          match = re.match(filter, table.name)
    348394          if not match: continue
    349           self.logger.info("   Reading IPP table " + table.name + " from FITS file")
     395          self.logger.info("Reading IPP table " + table.name + " from FITS file")
    350396          table = stilts.tpipe(table, cmd='explodeall')
    351397
    352398          # drop any previous tables before import
    353           self.scratchDb.dropTable(table.name)
     399          #self.scratchDb.dropTable(table.name)
    354400
    355401          # IPP FITS files are littered with infinities, so remove these
    356           self.logger.info("   Removing Infinity values from all columns")
     402          self.logger.debug("Removing Infinity values from all columns")
    357403          table = stilts.tpipe(table, cmd='replaceval -Infinity null *')
    358404          table = stilts.tpipe(table, cmd='replaceval Infinity null *')
     
    360406          try:
    361407              table.write(self.scratchDb.url + '#' + table.name)
     408              self.scratchDb.killLastConnectionID()
     409              count = count + 1
    362410          except:
    363               self.logger.exception("   Problem writing table '" + table.name + "' to the database")
    364           count = count + 1
     411              self.logger.exception("Problem writing table '" + table.name + "' to the database")
     412
    365413
    366414      self.logger.info("Done. Imported %d tables" % count)
    367 
    368415      self.indexIppTables()
    369416
     
    373420    def exportPspsTablesToFits(self, regex="(.*)"):
    374421
    375         self.logger.info("Replacing NULLs with -999 then exporting all PSPS tables to FITS")
     422        self.logger.info("Replacing NULLs with -999, changing tables names using regex: " + regex)
    376423        _tables = []
    377424
    378         self.logger.info("    Selecting database tables")
     425        self.logger.info("Selecting database tables")
    379426        for table in self.tablesToExport:
    380427
     
    383430
    384431           # get everything from table
    385            _table = stilts.tread(self.scratchDb.url + '#SELECT * FROM ' + table)
    386 
     432           try:
     433               _table = stilts.tread(self.scratchDb.url + '#SELECT * FROM ' + table)
     434               self.scratchDb.killLastConnectionID()
     435           except:
     436               self.logger.exception("Could not read from DB table: " + table)
     437               return False
     438               
    387439           # replace nulls and empty fields with weird PSPS -999 pseudo-null
    388440           _table = stilts.tpipe(_table, cmd='replaceval "" -999 *')
     
    395447           _tables.append(_table)
    396448
    397         self.logger.info("    Writing to FITS file '" + self.outputFitsPath + "'...")
    398         stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
    399         self.logger.info("    ...done")
    400         self.ippToPspsDb.updateProcessed(self.batchID, 1)
     449        self.logger.info("Writing to FITS file '" + self.outputFitsPath + "'...")
     450        try:
     451            stilts.twrites(_tables, self.outputFitsPath, fmt='fits')
     452            self.ippToPspsDb.updateProcessed(self.batchID, 1)
     453        except:
     454            self.logger.exception("Could not write to FITS")
     455            return False
     456
     457        return True
    401458
    402459    '''
     
    447504    '''
    448505    def alreadyProcessed(self):
    449            self.logger.info("Not implemented")
    450 
    451 
    452 
     506        self.logger.info("Not implemented")
     507
     508
     509    '''
     510    Creates and publishes a batch
     511    '''
     512    def run(self):
     513
     514        if not self.everythingOK: return
     515
     516        self.createEmptyPspsTables()
     517        self.importIppTables()
     518        if self.populatePspsTables():
     519            if self.exportPspsTablesToFits():
     520                self.writeBatchManifest()
     521                self.createTarball()
     522                self.publishToDatastore()
     523                #self.reportNullsInAllPspsTables(False)
     524                #sys.exit()
     525        self.logger.info("Finished.")
     526
     527
  • branches/czw_branch/20110406/ippToPsps/jython/detectionbatch.py

    r31434 r31606  
    66from java.lang import *
    77from java.sql import *
     8
    89from batch import Batch
    910from gpc1db import Gpc1Db
     11from ipptopspsdb import IppToPspsDb
     12from scratchdb import ScratchDb
    1013
    1114import logging.config
     
    1922    Constructor
    2023    '''
    21     def __init__(self, logger, camID, inputFile, test=False, useFullTables=False):
     24    def __init__(self,
     25                 logger,
     26                 gpc1Db,
     27                 ippToPspsDb,
     28                 scratchDb,
     29                 camID,
     30                 inputFile,
     31                 test=False,
     32                 useFullTables=False):
     33
    2234       super(DetectionBatch, self).__init__(
    2335               logger,
     36               gpc1Db,
     37               ippToPspsDb,
     38               scratchDb,
     39               camID,
    2440               "detection",
    2541               inputFile,
    26                "MD04",
    27                useFullTables) # TODO
     42               "MD04", # TODO
    2843               #"3PI") # TODO
    29 
    30        self.logger.info("DetectionBatch constructor. Creating batch from: '" + inputFile + "'")
    31 
    32        meta = self.gpc1Db.getCameraStageMeta(camID)
    33      
    34        self.expID = meta[0];
    35        self.expName = meta[1];
    36        self.distGroup = meta[2];
    37 
    38        self.logger.info("Processing exposure with ID: %d, name: %s and distribution group: %s" % (self.expID, self.expName, self.distGroup))
     44               useFullTables)
     45
     46       if not self.everythingOK: return
     47
     48       # meta data to the log
     49       self.logger.info("New Detection Batch:")
     50       self.logger.info("Cam ID:             %d" % self.id)
     51       self.logger.info("file:               %s" % inputFile)
     52       self.logger.info("Exp ID:             %d" % self.expID)
     53       self.logger.info("Exp name:           %s" % self.expName)
     54       self.logger.info("Distribution group: %s" % self.distGroup)
    3955
    4056       # create an output filename, which is {expID}.FITS
     
    167183        ," + self.header['PCA2X0Y2'] + " \
    168184        )"
    169         self.scratchDb.stmt.execute(sql)
     185        self.scratchDb.execute(sql)
    170186
    171187        self.scratchDb.updateAllRows("FrameMeta", "surveyID", str(self.surveyID))
     
    184200        self.scratchDb.dropTable(tableName)
    185201        sql = "CREATE TABLE " + tableName + " LIKE ImageMeta"
    186         try: self.scratchDb.stmt.execute(sql)
     202        try: self.scratchDb.execute(sql)
    187203        except: pass
    188204
     
    310326               )"
    311327
    312         self.scratchDb.stmt.execute(sql)
     328        self.scratchDb.execute(sql)
    313329        self.scratchDb.updateFilterID(tableName, self.filter)
    314330        self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
    315331        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
    316         self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO'])
     332        if 'NASTRO' in header: self.totalNumPhotoRef = self.totalNumPhotoRef + int(header['NASTRO'])
    317333        self.scratchDb.replaceNullsInThisColumn(tableName, "polyOrder", "0")
    318334
     
    327343        self.scratchDb.dropTable(tableName)
    328344        sql = "CREATE TABLE " + tableName + " LIKE Detection"
    329         try: self.scratchDb.stmt.execute(sql)
     345        try: self.scratchDb.execute(sql)
    330346        except: pass
    331347
     
    375391               ,EXT_NSIGMA \
    376392               FROM " + ota + "_psf"
    377 
    378         self.scratchDb.stmt.execute(sql)
     393        self.scratchDb.execute(sql)
    379394
    380395        # set obsTime
    381396        sql = "UPDATE " + tableName + " SET obsTime = %f, assocDate = '%s', activeFlag = 0" % (self.obsTime, self.dateStr)
    382         self.scratchDb.stmt.execute(sql)
     397        self.scratchDb.execute(sql)
    383398        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
    384399        self.scratchDb.updateAllRows(tableName, "historyModNum", "0")
     
    387402        self.scratchDb.updateFilterID(tableName, self.filter)
    388403
    389         # now delete bad flux
     404        # now delete bad flux and bad chip positions
    390405        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "instFlux")
    391406        self.scratchDb.reportAndDeleteRowsWithNULLS(tableName, "peakADU")
     
    401416        self.scratchDb.dropTable(tableName)
    402417        sql = "CREATE TABLE " + tableName + " LIKE SkinnyObject"
    403         try: self.scratchDb.stmt.execute(sql)
     418        try: self.scratchDb.execute(sql)
    404419        except: pass
    405420
     
    415430               ,surveyID \
    416431               FROM Detection_" + ota
    417         self.scratchDb.stmt.execute(sql)
     432        self.scratchDb.execute(sql)
    418433
    419434        self.scratchDb.updateAllRows(tableName, "dataRelease", str(self.dataRelease))
     
    429444        self.scratchDb.dropTable(tableName)
    430445        sql = "CREATE TABLE " + tableName + " LIKE ObjectCalColor"
    431         try: self.scratchDb.stmt.execute(sql)
     446        try: self.scratchDb.execute(sql)
    432447        except: pass
    433448
     
    443458               ,filterID \
    444459               FROM Detection_" + ota
    445         self.scratchDb.stmt.execute(sql)
     460        self.scratchDb.execute(sql)
    446461
    447462        self.scratchDb.updateAllRows(tableName, "calibModNum", str(self.calibModNum))
     
    484499
    485500        imageID = self.scratchDb.getImageIDFromExternID(sourceID, externID)
    486         self.logger.info("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
     501        self.logger.debug("Updating table '" + table + "' with DVO IDs using imageID = %d" % imageID)
    487502        sql = "UPDATE IGNORE " + table + " AS a, " + self.scratchDb.dvoDetection + " AS b SET \
    488503               a.ippObjID = b.ippObjID, \
     
    494509               AND b.imageID = " + str(imageID)
    495510
    496         self.scratchDb.stmt.execute(sql)
     511        self.scratchDb.execute(sql)
    497512
    498513
     
    511526
    512527        # loop through all OTAs and populate ImageMeta extensions
     528        self.logger.info("Reading all fits headers and populating ImageMeta tables")
    513529        for x in range(self.startX, self.endX):
    514530            for y in range(self.startY, self.endY):
     
    524540                # load corresponding header into memory
    525541                header = self.findAndReadFITSHeader(ota + ".hdr", file)
     542                if not header:
     543                    self.logger.error("No header found for OTA " + ota)
     544                    continue
     545
    526546
    527547                # store sourceID/imageID combo in Db so DVO can look up later
     
    578598
    579599                # update ImageMeta with count of detections for this OTA and photoCodeID
    580                 sql = "UPDATE ImageMeta_" + ota + " SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(sourceIDs[ota], imageIDs[ota]))
    581                 self.scratchDb.stmt.execute(sql)
     600                sql = "UPDATE ImageMeta_" + ota + " \
     601                       SET nDetect = %d, photoCalID = %d" % (self.scratchDb.getRowCount("Detection_" + ota), self.scratchDb.getPhotoCalID(sourceIDs[ota], imageIDs[ota]))
     602                self.scratchDb.execute(sql)
    582603
    583604                self.populateSkinnyObjectTable(ota)
     
    603624        # update FrameMeta with count OTAs in this file and total number of photometric reference sources
    604625        sql = "UPDATE FrameMeta SET nOTA = %d, numPhotoRef = %d" % (otaCount, self.totalNumPhotoRef)
    605         self.scratchDb.stmt.execute(sql)
     626        self.scratchDb.execute(sql)
    606627       
    607628        return True
     
    613634
    614635        sql = "UPDATE " + tableName + " SET imageID = %d%d%d" % (self.expID, x, y)
    615         self.scratchDb.stmt.execute(sql)
     636        self.scratchDb.execute(sql)
    616637
    617638    '''
     
    619640    '''
    620641    def alreadyProcessed(self):
     642
     643        meta = self.gpc1Db.getCameraStageMeta(self.id)
     644        self.expID = meta[0];
     645        self.expName = meta[1];
     646        self.distGroup = meta[2];
    621647
    622648        return self.ippToPspsDb.alreadyProcessed("detection", "exp_id", self.expID)
     
    634660
    635661
     662    '''
     663    Overriding this method. Filter to only import *.psf extensions
     664    '''
     665    def importIppTables(self, filter=""):
     666       return super(DetectionBatch, self).importIppTables(".*.psf")
     667
     668
     669    '''
     670    Overriding this method. Use regex to trim off, eg _XY33 extension
     671    '''
     672    def exportPspsTablesToFits(self, regex="(.*)"):
     673       return super(DetectionBatch, self).exportPspsTablesToFits("([a-zA-Z]+)")
     674
     675
     676# TODO put in config
     677useFullTables=True
     678testMode=False
     679
    636680logging.config.fileConfig("logging.conf")
    637681logger = logging.getLogger("detectionbatch")
     682logger.setLevel(logging.INFO)
    638683logger.info("Starting")
    639684
    640685gpc1Db = Gpc1Db(logger)
     686ippToPspsDb = IppToPspsDb(logger)
     687scratchDb = ScratchDb(logger, useFullTables)
     688
    641689camIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.V2", "cam")
    642690logger.info("Found %d exposures" % len(camIDs))
     
    645693for camID in camIDs:
    646694
    647     logger.info("-------------------------------------------------- cam ID: %d" % camID)
     695    #if camID < 43764: continue # TODO
    648696
    649697    file = gpc1Db.getCameraStageSmf(camID)
    650     if not os.path.isfile(file):
    651         logger.error("Cannot read file at '" + file)
    652         continue
    653 
    654     detectionBatch = DetectionBatch(logger, camID, file, False, True)
    655 
    656     if not detectionBatch.alreadyProcessed():
    657 
    658         detectionBatch.createEmptyPspsTables()
    659         detectionBatch.importIppTables(".*.psf")
    660         if detectionBatch.populatePspsTables():
    661             detectionBatch.exportPspsTablesToFits("([a-zA-Z]+)")
    662             detectionBatch.writeBatchManifest()
    663             #detectionBatch.reportNullsInAllPspsTables(False)
    664             #detectionBatch.createTarball()
    665             #detectionBatch.publishToDatastore()
    666    
    667             i = i+1
    668            # if i > 0: sys.exit()
    669 
     698
     699    detectionBatch = DetectionBatch(logger,
     700                                    gpc1Db,
     701                                    ippToPspsDb,
     702                                    scratchDb,
     703                                    camID,
     704                                    file,
     705                                    testMode,
     706                                    useFullTables)
     707    detectionBatch.run()
     708
  • branches/czw_branch/20110406/ippToPsps/jython/gpc1db.py

    r31434 r31606  
    2929        self.logger.debug("Gpc1Db destructor")
    3030
     31
     32    '''
     33    TODO
     34    '''
     35    def getIDsInThisDVODbForThisStageFudge(self):
     36
     37        sql = "SELECT staticskyRun.sky_id \
     38               FROM staticskyInput, staticskyRun, stackRun, staticskyResult \
     39               WHERE staticskyRun.sky_id = staticskyInput.sky_id \
     40               AND staticskyInput.stack_id = stackRun.stack_id \
     41               AND staticskyInput.sky_id = staticskyResult.sky_id \
     42               AND staticskyRun.label like 'MD04.staticsky' \
     43               AND stackRun.filter like 'i%'"
     44
     45        try:
     46            rs = self.executeQuery(sql)
     47        except:
     48            self.logger.exception("Can't query for ids in DVO")
     49
     50        ids = []
     51        while (rs.next()):
     52            ids.append(rs.getInt(1))
     53
     54        rs.close()
     55
     56        self.logger.info("Found %d items in DVO database '" % (len(ids)))
     57
     58        return ids
     59
    3160    '''
    3261    Gets a list of ids in this DVO database for this stage, could be cam or staticsky (so far)
     
    4069
    4170        try:
    42             rs = self.stmt.executeQuery(sql)
     71            rs = self.executeQuery(sql)
    4372        except:
    4473            self.logger.exception("Can't query for ids in DVO")
     
    5079        rs.close()
    5180
    52         self.logger.debug("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
     81        self.logger.info("Found %d items in DVO database '%s' for stage='%s'" % (len(ids), dvoDb, stage))
    5382
    5483        return ids
     
    73102
    74103        try:
    75             rs = self.stmt.executeQuery(sql)
     104            rs = self.executeQuery(sql)
    76105        except:
    77106            self.logger.exception("Can't query for imageIDs")
     
    105134
    106135        try:
    107             rs = self.stmt.executeQuery(sql)
     136            rs = self.executeQuery(sql)
    108137            rs.first()
    109138            meta.append(rs.getInt(1))
     
    113142
    114143        return meta
     144
    115145    '''
    116146    Gets some camera-stage meta data for this cam_id
     
    127157
    128158        try:
    129             rs = self.stmt.executeQuery(sql)
     159            rs = self.executeQuery(sql)
    130160            rs.first()
    131161            meta.append(rs.getInt(1))
     
    150180
    151181        try:
    152             rs = self.stmt.executeQuery(sql)
     182            rs = self.executeQuery(sql)
    153183            rs.first()
    154184        except:
     
    171201            files = glob.glob(path + "/*.cmf")
    172202
     203        if len(files) < 1: return "NULL"
     204
    173205        return files[0] # TODO just returning first file - check
    174206
     
    186218
    187219        try:
    188             rs = self.stmt.executeQuery(sql)
     220            rs = self.executeQuery(sql)
    189221            rs.first()
    190222        except:
     
    200232
    201233            f=os.popen("neb-ls -p "+path+"%cmf")
    202             print "neb-ls -p "+path+"%cmf"
    203234            for i in f.readlines():
    204235                files.append(i.rstrip())
    205                 print i.rstrip()
    206236
    207237        # or not a neb path
     
    211241        return files
    212242
     243
     244    '''
     245    TODO hack to get exposure time for a stack
     246    '''
     247    def getStackExpTime(self, stackID):
     248
     249        self.logger.debug("Querying GPC1 for stack exposure time")
     250
     251        sql = "SELECT SUM(exp_time) * (COUNT(warp_id) - reject_images) / COUNT(warp_id) as EXPTIME \
     252               FROM staticskyRun JOIN staticskyInput using(sky_id) \
     253               JOIN stackRun using(stack_id) \
     254               JOIN stackSumSkyfile using(stack_id) \
     255               JOIN stackInputSkyfile using(stack_id) \
     256               JOIN warpRun using(warp_id) \
     257               JOIN fakeRun using(fake_id) \
     258               JOIN camRun using(cam_id) \
     259               JOIN chipRun using(chip_id) \
     260               JOIN rawExp using(exp_id) \
     261               WHERE stack_id = %d" % stackID
     262
     263        try:
     264            rs = self.executeQuery(sql)
     265            rs.first()
     266            return rs.getInt(1)
     267        except:
     268            self.logger.exception("Can't query for exposure time")
     269
     270        return 0.0
     271
     272
  • branches/czw_branch/20110406/ippToPsps/jython/ipptopspsdb.py

    r31434 r31606  
    3737               )"
    3838
    39         self.stmt.execute(sql)
     39        self.execute(sql)
    4040
    4141        sql = "SELECT MAX(batch_id) FROM batch"
     
    4444
    4545        try:
    46             rs = self.stmt.executeQuery(sql)
     46            rs = self.executeQuery(sql)
    4747            rs.first()
    4848            batchID = rs.getInt(1)
     
    6464               WHERE batch_id = " + str(batchID)
    6565
    66         self.stmt.execute(sql)
     66        self.execute(sql)
    6767
    6868    '''
     
    7575               WHERE batch_id = " + str(batchID)
    7676
    77         self.stmt.execute(sql)
     77        self.execute(sql)
    7878
    7979    '''
     
    8686               WHERE batch_id = " + str(batchID)
    8787
    88         self.stmt.execute(sql)
     88        self.execute(sql)
    8989
    9090    '''
     
    101101
    102102        try:
    103             rs = self.stmt.executeQuery(sql)
     103            rs = self.executeQuery(sql)
    104104            rs.first()
    105105            if rs.getInt(1) > 0:
     
    128128               )"
    129129
    130         self.stmt.execute(sql)
     130        self.execute(sql)
    131131
    132132    '''
     
    149149               )"
    150150
    151         self.stmt.execute(sql)
     151        self.execute(sql)
    152152
    153153
  • branches/czw_branch/20110406/ippToPsps/jython/mysql.py

    r31434 r31606  
    3737        self.url = "jdbc:mysql://"+self.dbHost+"/"+self.dbName+"?user="+self.dbUser+"&password="+self.dbPass
    3838        self.con = DriverManager.getConnection(self.url)
    39         self.stmt = self.con.createStatement()
     39        self.connectionID = self.getLastConnectionID()
     40        self.logger.info("MySQL connection to %s with ID %d" % (dbType, self.connectionID))
     41
     42        #self.stmt = self.con.createStatement()
     43
     44
     45    '''
     46    Disconnect from database
     47    '''
     48    def disconnect(self):
     49        self.con.close()
    4050
    4151    '''
     
    4555
    4656        self.logger.debug("MySql destructor")
    47         self.stmt.close()
    48         self.con.close()
     57        self.disconnect()
     58
     59    '''
     60    Kills the last connection ID, so long as it's not THIS connection ID
     61    '''
     62    def killLastConnectionID(self):
     63   
     64        connectionID = self.getLastConnectionID()
     65        if connectionID == self.connectionID:
     66            self.logger.error("NOT going to kill THIS connection ID")
     67            return
     68
     69        sql = "KILL %d" % connectionID
     70        self.execute(sql)
     71
     72    '''
     73    Gets the last connection ID
     74    '''
     75    def getLastConnectionID(self):
     76
     77        sql = "SELECT ID \
     78               FROM INFORMATION_SCHEMA.PROCESSLIST \
     79               WHERE DB='" + self.dbName + "' \
     80               ORDER BY ID"
     81        rs = self.executeQuery(sql)
     82        rs.last()
     83        return rs.getInt(1)
    4984
    5085    '''
     
    5489
    5590        sql = "UPDATE " + table + " SET " + column + " = " + value
    56         self.stmt.execute(sql)
     91        self.execute(sql)
    5792
    5893    '''
     
    6297
    6398        sql = "DROP TABLE " + table
    64         try: self.stmt.execute(sql)
     99        try: self.execute(sql)
    65100        except: return
    66101
     
    74109        sql = "ALTER TABLE " + table + " ADD UNIQUE (" + column + ")"
    75110        try:
    76             self.stmt.execute(sql)
     111            self.execute(sql)
    77112        except: pass
    78113            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
     
    82117    def createIndex(self, table, column):
    83118
    84         self.logger.debug("Creating index on column '"+column+"' for table '"+table+"'")
     119        #self.logger.debug("Creating index on column '"+column+"' for table '"+table+"'")
    85120
    86121        sql = "CREATE INDEX "+table+"_"+column+"_index ON "+table+" ("+column+")"
    87122        try:
    88             self.stmt.execute(sql)
     123            self.execute(sql)
    89124        except: pass
    90125            #self.logger.warn("Index already in place on '" + column + "' for table '" + table + "'")
     126    '''
     127    TODO
     128    '''
     129    def execute(self, sql):
     130
     131        stmt = self.con.createStatement()
     132        stmt.execute(sql)
     133        stmt.close()
     134
     135    '''
     136    TODO
     137    '''
     138    def executeQuery(self, sql):
     139
     140        stmt = self.con.createStatement()
     141        rs = stmt.executeQuery(sql)
     142        #stmt.close()
     143        return rs
    91144
    92145    '''
     
    96149
    97150       sql = "SHOW COLUMNS FROM " + tableName
    98        rs = self.stmt.executeQuery(sql)
     151       rs = self.executeQuery(sql)
    99152       columns = []
    100153       while (rs.next()): columns.append(rs.getString(1))
     
    109162
    110163      sql = "UPDATE " + tableName + " SET " + column + " = " + sub + " WHERE " + column + " IS NULL"
    111       self.stmt.execute(sql)
     164      self.execute(sql)
    112165
    113166    '''
     
    123176         
    124177          sql = "UPDATE " + tableName + " SET " + column + " = " + sub + " WHERE " + column + " IS NULL"
    125           self.stmt.execute(sql)
     178          self.execute(sql)
    126179
    127180    '''
     
    131184
    132185        sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + columnName + " = " + value
    133         rs = self.stmt.executeQuery(sql)
     186        rs = self.executeQuery(sql)
    134187        rs.first()
    135         nBadFlux = rs.getInt(1)
    136         self.logger.info("%d NULL %s values in table %s. Deleting." % (nBadFlux, columnName, tableName))
     188        nBad = rs.getInt(1)
     189        self.logger.info("%5d NULL %s values in table %s. Deleting." % (nBad, columnName, tableName))
    137190
    138191        sql="DELETE from " + tableName + " WHERE " + columnName + " = " + value
    139         self.stmt.execute(sql)
     192        self.execute(sql)
    140193
    141194    '''
     
    145198
    146199        sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + columnName + " IS NULL"
    147         rs = self.stmt.executeQuery(sql)
     200        rs = self.executeQuery(sql)
    148201        rs.first()
    149         nBadFlux = rs.getInt(1)
    150         self.logger.info("%d NULL %s values in table %s. Deleting." % (nBadFlux, columnName, tableName))
     202        nBad = rs.getInt(1)
     203        self.logger.info("%5d NULL %s values in table %s. Deleting." % (nBad, columnName, tableName))
    151204
    152205        sql="DELETE from " + tableName + " WHERE " + columnName + " IS NULL"
    153         self.stmt.execute(sql)
     206        self.execute(sql)
    154207
    155208    '''
     
    160213       # first, count rows
    161214       sql = "SELECT COUNT(*) FROM " + tableName
    162        rs = self.stmt.executeQuery(sql)
     215       rs = self.executeQuery(sql)
    163216       rs.first()
    164217       numRows = rs.getInt(1)
     
    175228         
    176229          sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + column + " IS NULL"
    177           rs = self.stmt.executeQuery(sql)
     230          rs = self.executeQuery(sql)
    178231          rs.first()
    179232          if rs.getInt(1) == numRows:
     
    191244        sql = "SELECT COUNT(*) FROM " + table
    192245        try:
    193             rs = self.stmt.executeQuery(sql) 
     246            rs = self.executeQuery(sql) 
    194247            rs.first()
    195248            return rs.getInt(1)
  • branches/czw_branch/20110406/ippToPsps/jython/scratchdb.py

    r31434 r31606  
    4545        sql = "SELECT surveyID FROM Survey WHERE name = '" + name + "'"
    4646        try:
    47             rs = self.stmt.executeQuery(sql)
     47            rs = self.executeQuery(sql)
    4848            rs.first()
    4949            return rs.getInt(1)
     
    6161        sql = "SELECT flags FROM " + self.dvoMeta + " WHERE sourceID = %s AND externID = %s" % (sourceID, externID)
    6262        try:
    63             rs = self.stmt.executeQuery(sql) 
     63            rs = self.executeQuery(sql) 
    6464            rs.first()
    6565            flags = rs.getInt(1)
     
    7878        sql = "SELECT imageID FROM " + self.dvoMeta + " WHERE sourceID = %s AND externID = %s" % (sourceID, externID)
    7979        try:
    80             rs = self.stmt.executeQuery(sql) 
     80            rs = self.executeQuery(sql) 
    8181            rs.first()
    8282            imageID = rs.getInt(1)
     
    9595        sql = "SELECT photcode FROM " + self.dvoMeta + " WHERE sourceID = %s AND externID = %s" % (sourceID, externID)
    9696        try:
    97             rs = self.stmt.executeQuery(sql) 
     97            rs = self.executeQuery(sql) 
    9898            rs.first()
    9999            photcode = rs.getInt(1)
     
    109109
    110110        sql = "UPDATE "+table+" AS a, Filter AS b SET a.filterID=b.filterID WHERE b.filterType = '" + filter + "'"
    111         self.stmt.execute(sql)
     111        self.execute(sql)
    112112
    113113    '''
     
    123123               " + str(imageID) + "    \
    124124               )"
    125         self.stmt.execute(sql)
     125        self.execute(sql)
    126126
    127127    '''
     
    131131
    132132        sql = "INSERT INTO dvoDone (name) VALUES ('" + name + "')"
    133         self.stmt.execute(sql)
     133        self.execute(sql)
    134134       
    135135    '''
     
    141141
    142142        try:
    143             rs = self.stmt.executeQuery(sql)
     143            rs = self.executeQuery(sql)
    144144            rs.first()
    145145            if rs.getInt(1) > 0:
     
    160160
    161161        sql = "DROP TABLE dvoMeta"
    162         try: self.stmt.execute(sql)
     162        try: self.execute(sql)
    163163        except: pass
    164164       
    165165        sql = "DROP TABLE dvoDetection"
    166         try: self.stmt.execute(sql)
     166        try: self.execute(sql)
    167167        except: pass
    168168
     
    175175               )"
    176176
    177         try: self.stmt.execute(sql)
     177        try: self.execute(sql)
    178178        except:
    179179            self.logger.error("Unable to create DVO meta-data database table")
     
    193193               #INDEX (ippDetectID) \
    194194
    195         try: self.stmt.execute(sql)
     195        try: self.execute(sql)
    196196        except:
    197197            self.logger.error("Unable to create DVO detection database table")
  • branches/czw_branch/20110406/ippToPsps/jython/stackbatch.py

    r31434 r31606  
    88from java.sql import *
    99
     10from batch import Batch
    1011from gpc1db import Gpc1Db
    11 from batch import Batch
     12from ipptopspsdb import IppToPspsDb
     13from scratchdb import ScratchDb
     14
    1215import logging.config
    1316
     
    2023    Constructor
    2124    '''
    22     def __init__(self, logger, skyID, inputFile, stackType, useFullTables=False):
     25    def __init__(self,
     26                 logger,
     27                 gpc1Db,
     28                 ippToPspsDb,
     29                 scratchDb,
     30                 skyID,
     31                 inputFile,
     32                 stackType,
     33                 useFullTables=False):
     34
    2335       super(StackBatch, self).__init__(
    2436               logger,
     37               gpc1Db,
     38               ippToPspsDb,
     39               scratchDb,
     40               skyID,
    2541               "stack",
    2642               inputFile,
     
    2844               useFullTables) # TODO
    2945
    30        self.logger.info("StackBatch constructor. Creating batch from: '" + inputFile + "'")
    31 
    32        self.skyID = skyID
    33 
    34        # get filterID using init table
    35        self.filter = self.header['FPA.FILTER']
    36        self.filter = self.filter[0:1]
    37 
    38        self.stackType = stackType
    39        meta = self.gpc1Db.getStackStageMeta(self.skyID, self.header['FPA.FILTER'])
    40        if len(meta) < 1: return
    41        self.stackID = meta[0];
    42        self.skycell = meta[1];
    43 
    44        # determine skycell from header value
    45        #self.skycell = "skycell.34" #= self.header['SKYCELL']
    46        self.skycell = self.skycell[8:]
    47 
    48        self.logger.info("Processing stack with ID: %d, type: %s and skycell: %s filter: %s" % (self.stackID, self.stackType, self.skycell, self.filter))
    49 
     46       if not self.everythingOK: return
     47
     48       self.expTime = gpc1Db.getStackExpTime(self.stackID)
     49
     50       self.logger.info("got exp time of %d" % self.expTime)
     51
     52       # meta data to the log
     53       self.logger.info("New Stack Batch:")
     54       self.logger.info("Sky ID:     %d" % self.id)
     55       self.logger.info("File:       %s" % inputFile)
     56       self.logger.info("Stack ID:   %d" % self.stackID)
     57       self.logger.info("Stack type: %s" % self.stackType)
     58       self.logger.info("Skycell:    %s" % self.skycell)
     59       self.logger.info("Filter:     %s" % self.filter)
    5060
    5161       # delete PSPS tables
     
    5868       self.scratchDb.dropTable("ObjectCalColor")
    5969
    60        # delete IPP tables
    61        #self.scratchDb.dropTable("SkyChip_psf")
    62        #self.scratchDb.dropTable("SkyChip_xsrc")
    63        #self.scratchDb.dropTable("SkyChip_xfit")
    64        #self.scratchDb.dropTable("SkyChip_xrad")
    65 
    66        self.logger.info("Stack type: " + self.safeDictionaryAccess(self.header, self.stackType))
    67        # obs time makes no sense except for nightly stacks
    68        #if self.header['STK_TYPE'] != "NIGHTLY_STACK": self.header['MJD-OBS'] = "-999"
    69 
    7070       # create an output filename, which is {filterID}{skycellID}.FITS
    71        self.outputFitsFile = "%s%07d.FITS" % (self.filter, int(self.skycell))
     71       self.outputFitsFile = "%08d.FITS" % self.stackID
    7272       self.outputFitsPath = "%s/%s" % (self.localOutPath, self.outputFitsFile)
    7373
     
    7777
    7878       # insert what we know about this stack batch into the stack table
    79        self.ippToPspsDb.insertStackMeta(self.batchID, self.skyID, self.stackID, self.filter, self.stackType)
     79       self.ippToPspsDb.insertStackMeta(self.batchID, self.id, self.stackID, self.filter, self.stackType)
    8080
    8181       # insert sourceID/imageID combo so DVO can look it up
     
    8989
    9090        sql = "UPDATE " + table + "  SET stackMetaID=" + str(self.stackID)
    91         self.scratchDb.stmt.execute(sql)
     91        self.scratchDb.execute(sql)
    9292
    9393    '''
     
    9797
    9898        sql = "UPDATE "+table+" AS a, StackType AS b SET a.stackTypeID=b.stackTypeID WHERE b.name = '" + self.stackType + "'"
    99         self.scratchDb.stmt.execute(sql)
     99        self.scratchDb.execute(sql)
    100100
    101101
     
    148148        WHERE a.ippDetectID=b.IPP_IDET AND b.PSF_FWHM "+psfCondition
    149149
    150         self.scratchDb.stmt.execute(sql)
     150        self.scratchDb.execute(sql)
    151151
    152152    '''
     
    196196        WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
    197197
    198         self.scratchDb.stmt.execute(sql)
     198        self.scratchDb.execute(sql)
    199199
    200200        # sersic fit has an extra parameter
     
    213213            WHERE a.ippDetectID=b.IPP_IDET AND b.MODEL_TYPE = '"+ippModelType+"'"
    214214
    215             self.scratchDb.stmt.execute(sql)
     215            self.scratchDb.execute(sql)
    216216
    217217
     
    220220    '''
    221221    def populateStackMeta(self):
     222
    222223        self.logger.info("Procesing StackMeta table")
    223224
     
    246247        ," + str(self.scratchDb.getPhotoCalID(self.header['SOURCEID'], self.header['IMAGEID'])) + " \
    247248        ," + self.header['FPA.ZP'] + " \
    248         ," + self.header['EXPTIME'] + " \
     249        ," + str(self.expTime) + " \
    249250        ,'" + self.safeDictionaryAccess(self.header, 'PSFMODEL') + "' \
    250251        ,'" + self.header['CTYPE1'] + "' \
     
    261262        ," + self.header['PC002002'] + " \
    262263        )"
    263         self.scratchDb.stmt.execute(sql)
     264        self.scratchDb.execute(sql)
    264265
    265266        self.scratchDb.updateAllRows("StackMeta", "surveyID", str(self.surveyID))
     
    272273    '''
    273274    def populateStackDetection(self):
     275
    274276        self.logger.info("Procesing StackDetection table")
    275277
     
    321323               ,X_PSF_SIG \
    322324               ,Y_PSF_SIG \
    323                ,POW(10.0, (-0.4*PSF_INST_MAG)) / "+self.header['EXPTIME']+" \
    324                ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / "+self.header['EXPTIME']+")) / 1.085736) \
    325                ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / "+self.header['EXPTIME']+" \
     325               ,POW(10.0, (-0.4*PSF_INST_MAG)) / "+str(self.expTime)+" \
     326               ,ABS((PSF_INST_MAG_SIG*(POW(10.0, (-0.4*PSF_INST_MAG)) / "+str(self.expTime)+")) / 1.085736) \
     327               ,POW(10.0, (-0.4*PEAK_FLUX_AS_MAG)) / "+str(self.expTime)+" \
    326328               ,SKY \
    327329               ,SKY_SIGMA \
     
    352354               FROM SkyChip_psf"
    353355
    354         self.scratchDb.stmt.execute(sql)
     356        self.scratchDb.execute(sql)
    355357
    356358        self.scratchDb.updateAllRows("StackDetection", "surveyID", str(self.surveyID))
     
    362364        self.updateStackTypeID("StackDetection")
    363365        self.updateDvoIDs("StackDetection")
    364 
    365         # now delete bad flux
     366        sql = "ALTER TABLE StackDetection ADD PRIMARY KEY (objID, stackDetectID)"
     367        self.scratchDb.execute(sql)
     368
     369        if self.stackType == "DEEP_STACK":
     370
     371            #if deep stack and instFlux = null and err not null
     372            sql = "UPDATE StackDetection AS a, SkyChip_psf AS b \
     373                   SET instFlux = 2*b.PSF_INST_FLUX_SIG \
     374                   WHERE instFlux IS NULL \
     375                   AND b.PSF_INST_FLUX_SIG IS NOT NULL"
     376            self.scratchDb.execute(sql)
     377            #    instFlux = 2*PSF_INST_FLUX_SIG
     378           
    366379        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "instFlux")
    367380        self.scratchDb.reportAndDeleteRowsWithNULLS("StackDetection", "objID")
     
    372385    '''
    373386    def populateStackApFlx(self):
     387
    374388        self.logger.info("Procesing StackApFlx table")
    375389 
     
    381395
    382396        try:
    383             self.scratchDb.stmt.execute(sql)
     397            self.scratchDb.execute(sql)
    384398        except: return
    385399
    386400        # TODO temporarily loading 1st convolved fluxes into unconvolved fields
    387         self.logger.info("    Adding un-convolved fluxes")
     401        self.logger.info("Adding un-convolved fluxes")
    388402        self.updateApFlxs("", "< 7.0")
    389         self.logger.info("    Adding 1st convolved fluxes")
     403        self.logger.info("Adding 1st convolved fluxes")
    390404        self.updateApFlxs("c1", "< 7.0")
    391         self.logger.info("    Adding 2nd convolved fluxes")
     405        self.logger.info("Adding 2nd convolved fluxes")
    392406        self.updateApFlxs("c2", "> 7.0")
    393407
    394         self.logger.info("    Adding petrosians for extended sources")
     408        self.logger.info("Adding petrosians for extended sources")
    395409        sql = "UPDATE StackApFlx AS a, SkyChip_xsrc AS b SET \
    396410        petRadius=b.PETRO_RADIUS \
     
    403417        ,petR90Err=b.PETRO_RADIUS_90_ERR \
    404418        WHERE a.ippDetectID=b.IPP_IDET"
    405         self.scratchDb.stmt.execute(sql)
     419        self.scratchDb.execute(sql)
    406420
    407421        self.scratchDb.updateAllRows("StackApFlx", "surveyID", str(self.surveyID))
     
    413427        self.updateStackTypeID("StackApFlx")
    414428        self.updateDvoIDs("StackApFlx")
     429        self.scratchDb.reportAndDeleteRowsWithNULLS("StackApFlx", "objID")
     430        self.deleteDetectionsNotInStackDetection("StackApFlx")
     431
    415432
    416433    '''
     
    418435    '''
    419436    def populateStackModelFit(self):
     437
    420438        self.logger.info("Procesing StackModelFit table")
    421439
     
    423441        sql = "INSERT INTO StackModelFit (ippDetectID) SELECT DISTINCT IPP_IDET from SkyChip_xfit"
    424442        try:
    425             self.scratchDb.stmt.execute(sql)
     443            self.scratchDb.execute(sql)
    426444        except:
    427445            return
    428446
    429 
    430447        # populate model parameters
    431         self.logger.info("    Adding deVaucouleurs fit")
     448        self.logger.info("Adding deVaucouleurs fit")
    432449        self.updateModelFit("deV", "PS_MODEL_DEV")
    433         self.logger.info("    Adding exponential fit")
     450        self.logger.info("Adding exponential fit")
    434451        self.updateModelFit("exp", "PS_MODEL_EXP")
    435         self.logger.info("    Adding sersic fit")
     452        self.logger.info("Adding sersic fit")
    436453        self.updateModelFit("ser", "PS_MODEL_SERSIC")
    437454
     
    444461        self.updateStackTypeID("StackModelFit")
    445462        self.updateDvoIDs("StackModelFit")
     463        self.scratchDb.reportAndDeleteRowsWithNULLS("StackModelFit", "objID")
     464        self.deleteDetectionsNotInStackDetection("StackModelFit")
     465
     466    '''
     467    Reports and deletes detections in this table that are not in StackDetection
     468    '''
     469    def deleteDetectionsNotInStackDetection(self, table):
     470
     471        sql = "SELECT COUNT(*) FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
     472        rs = self.scratchDb.executeQuery(sql)
     473        rs.first()
     474        nMissing = rs.getInt(1)
     475        self.logger.info("%5d detections in %s table that are not in StackDetection. Deleting" % (nMissing, table))
     476 
     477        if nMissing < 1: return
     478       
     479        sql = "DELETE FROM " + table + " WHERE ippDetectID NOT IN (SELECT ippDetectID FROM StackDetection)"
     480        self.scratchDb.execute(sql)
     481       
    446482
    447483    '''
     
    449485    '''
    450486    def populateStackToImage(self):
     487
    451488        self.logger.info("Procesing StackToImage table")
    452489
     
    457494                   VALUES (\
    458495                   " + str(self.stackID) + ", " + imageID + ")"
    459             self.scratchDb.stmt.execute(sql)
     496            self.scratchDb.execute(sql)
    460497
    461498        # now update StackMeta with correct number of inputs
    462499        sql = "UPDATE StackMeta SET nP2Images = (SELECT COUNT(*) FROM StackToImage)"
    463         self.scratchDb.stmt.execute(sql)
     500        self.scratchDb.execute(sql)
    464501
    465502    '''
     
    467504    '''
    468505    def populateSkinnyObject(self):
     506
    469507        self.logger.info("Procesing SkinnyObject table")
    470508
     
    474512               ) \
    475513               SELECT \
    476                objID \
     514               DISTINCT objID \
    477515               ,ippObjID \
    478516               FROM StackDetection"
    479         self.scratchDb.stmt.execute(sql)
     517        self.scratchDb.execute(sql)
    480518
    481519        self.scratchDb.updateAllRows("SkinnyObject", "surveyID", str(self.surveyID))
     
    486524    '''
    487525    def populateObjectCalColor(self):
     526
    488527        self.logger.info("Procesing ObjectCalColor table")
    489528
     
    493532               ) \
    494533               SELECT \
    495                objID \
     534               DISTINCT objID \
    496535               ,ippObjID \
    497536               FROM StackDetection"
    498         self.scratchDb.stmt.execute(sql)
     537        self.scratchDb.execute(sql)
    499538
    500539        self.scratchDb.updateFilterID("ObjectCalColor", self.filter)
     
    508547
    509548        self.logger.info("Altering PSPS tables")
    510         self.scratchDb.makeColumnUnique("StackDetection", "objID")
     549        #self.scratchDb.makeColumnUnique("StackDetection", "objID")
    511550        self.scratchDb.createIndex("StackDetection", "ippDetectID")
    512551        self.scratchDb.createIndex("StackApFlx", "ippDetectID")
     
    531570        imageID = self.scratchDb.getImageIDFromExternID(self.header['SOURCEID'], self.header['IMAGEID'])
    532571
    533         self.logger.info("Updating table '" + table + "' with DVO IDs...")
     572        self.logger.debug("Updating table '" + table + "' with DVO IDs...")
    534573        sql = "UPDATE IGNORE " + table + " AS a, dvoDetectionFull AS b SET \
    535574               a.ippObjID = b.ippObjID, \
     
    539578               AND b.sourceID = " + self.header['SOURCEID'] + "\
    540579               AND b.imageID = " + str(imageID)
    541         self.scratchDb.stmt.execute(sql)
    542 
     580        self.scratchDb.execute(sql)
    543581
    544582    '''
     
    553591        self.populateStackMeta()
    554592        self.populateStackDetection()
    555         self.populateStackModelFit()
    556         self.populateStackApFlx()
     593
     594        if self.stackType != "NIGHTLY_STACK":
     595            self.populateStackModelFit()
     596            self.populateStackApFlx()
     597   
    557598        self.populateStackToImage()
    558599        self.populateSkinnyObject()
     
    560601
    561602        self.setMinMaxObjID(["StackDetection"])
    562        
     603       
     604        if self.totalDetections < 1:
     605
     606            self.logger.error("No detections to publish")
     607            return False
     608
    563609        return True
    564610
     
    568614    def alreadyProcessed(self):
    569615
    570         return self.ippToPspsDb.alreadyProcessed("stack", "stack_id", self.stackID)
     616        # sadly, we have to read the FITS primary header first
     617        if not self.readPrimaryHeader(): return False
     618
     619        # get filterID using init table
     620        self.filter = self.header['FPA.FILTER']
     621        self.filter = self.filter[0:1]
     622
     623        self.stackType = stackType
     624        meta = self.gpc1Db.getStackStageMeta(self.id, self.header['FPA.FILTER'])
     625        if len(meta) < 1: return False
     626        self.stackID = meta[0];
     627        self.skycell = meta[1];
     628        self.skycell = self.skycell[8:]
     629
     630        #return self.ippToPspsDb.alreadyProcessed("stack", "stack_id", self.stackID)
     631        return False # TODOI
     632
     633
     634useFullTables=True
    571635
    572636logging.config.fileConfig("logging.conf")
    573637logger = logging.getLogger("stackbatch")
     638logger.setLevel(logging.INFO)
    574639logger.info("Starting")
     640
    575641gpc1Db = Gpc1Db(logger)
    576 stackType = "NIGHTLY_STACK"
    577 skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.Staticsky", "staticsky")
    578 #skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.GENE.PSPSDEEP", "staticsky")
    579 #stackType = "DEEP_STACK"
    580 #skyIDs = [689]
     642ippToPspsDb = IppToPspsDb(logger)
     643scratchDb = ScratchDb(logger, useFullTables)
     644
     645#stackType = "NIGHTLY_STACK"
     646#skyIDs = gpc1Db.getIDsInThisDVODbForThisStageFudge()
     647#skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.Staticsky", "staticsky")
     648
     649stackType = "DEEP_STACK"
     650skyIDs = gpc1Db.getIDsInThisDVODbForThisStage("MD04.GENE.PSPSDEEP", "staticsky")
     651
     652#skyIDs = [942]
    581653#skyIDs = [299]
    582654#skyIDs = [302]
    583655#skyIDs = [8508]
    584 i = 0
     656#i = 0
    585657for skyID in skyIDs:
    586 
    587     logger.info("-------------------------------------------------- sky ID: %d" % skyID)
     658   
     659    #if skyID < 1340: continue # nightly
     660    #if skyID < 238: continue # deep
    588661
    589662    cmfFiles = gpc1Db.getStackStageCmfs(skyID)
     
    591664    for file in cmfFiles:
    592665
    593         if not os.path.isfile(file):
    594             logger.error("Cannot read file at '" + file)
    595             continue
    596 
    597         stackBatch = StackBatch(logger, skyID, file, stackType, True)
    598 
    599         if not stackBatch.alreadyProcessed():
    600 
    601             stackBatch.createEmptyPspsTables()
    602             stackBatch.importIppTables("")
    603             if stackBatch.populatePspsTables():
    604  
    605                 #stackBatch.reportNullsInAllPspsTables(False)
    606                 stackBatch.exportPspsTablesToFits()
    607                 stackBatch.writeBatchManifest()
    608                 #stackBatch.createTarball()
    609                 #stackBatch.publishToDatastore()
    610 
    611                 i = i + 1
    612                 #if i > 0: sys.exit()
    613 
    614 logger.info("Finished")
     666        stackBatch = StackBatch(logger,
     667                                gpc1Db,
     668                                ippToPspsDb,
     669                                scratchDb,
     670                                skyID,
     671                                file,
     672                                stackType,
     673                                useFullTables)
     674
     675        stackBatch.run()
     676
  • branches/czw_branch/20110406/ippTools/share/addtool_find_sky_id.sql

    r31434 r31606  
    33FROM
    44     staticskyResult
    5 join staticSkyRun using (sky_id)
    6 join staticSkyInput using (stack_id)
     5join staticskyRun using (sky_id)
     6join staticskyInput using(sky_id)
    77JOIN stackRun USING(stack_id)
    88
     
    1313          ) as foo
    1414     ON sky_id = added_sky_id
    15      AND stage = 'sky'
     15     AND stage = 'staticsky'
    1616     -- hook for qualifying the join on the previous_dvodb
    1717     AND %s
  • branches/czw_branch/20110406/ippTools/share/addtool_find_sky_id_dvo.sql

    r31434 r31606  
    11SELECT staticskyRun.* FROM staticskyResult
    22JOIN staticskyRun USING(sky_id)
     3join staticskyInput using(sky_id)
     4JOIN stackRun USING(stack_id)
     5
    36WHERE staticskyRun.state = 'full' and staticskyResult.quality = 0
    47    AND sky_id NOT IN (SELECT sky_id
  • branches/czw_branch/20110406/ippTools/share/camtool_find_pendingimfile.sql

  • branches/czw_branch/20110406/ippTools/share/pxadmin_create_tables.sql

  • branches/czw_branch/20110406/ippTools/share/regtool_pendingimfile.sql

    r25418 r31606  
    88    newImfile.uri,
    99    newImfile.bytes,
    10     newImfile.md5sum
     10    newImfile.md5sum,
     11    summitExp.dateobs AS summit_dateobs
    1112FROM newImfile
    1213JOIN newExp
    1314    USING(exp_id)
     15JOIN summitExp USING(summit_id)
    1416LEFT JOIN rawImfile
    1517    ON newExp.exp_id = rawImfile.exp_id
  • branches/czw_branch/20110406/ippTools/src

  • branches/czw_branch/20110406/ippTools/src/addtool.c

    r31434 r31606  
    117117
    118118    psMetadata *where = psMetadataAlloc();
    119     pxcamGetSearchArgs (config, where);
     119    //  pxcamGetSearchArgs (config, where);
    120120    PXOPT_COPY_S64(config->args, where,  "-cam_id",    "camRun.cam_id", "==");
    121121    PXOPT_COPY_S64(config->args, where,  "-stack_id",    "stackRun.stack_id", "==");
     
    123123    PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
    124124    if (strcmp(stage, "cam")== 0) {
    125 
     125      pxcamGetSearchArgs (config, where);
    126126    pxAddLabelSearchArgs (config, where, "-label",     "camRun.label", "=="); // define using camRun label
    127127    pxAddLabelSearchArgs (config, where, "-data_group","camRun.data_group", "=="); // define using camRun label
     128
    128129    PXOPT_COPY_STR(config->args, where,  "-reduction", "camRun.reduction", "==");
    129130    }
     
    133134    pxAddLabelSearchArgs (config, where, "-data_group","stackRun.data_group", "=="); // define using camRun label
    134135    PXOPT_COPY_STR(config->args, where,  "-reduction", "stackRun.reduction", "==");
     136    pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
    135137    }
    136138    if (strcmp(stage, "staticsky")== 0) {
     
    139141    pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label
    140142    PXOPT_COPY_STR(config->args, where,  "-reduction", "staticskyyRun.reduction", "==");
     143    pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
    141144    }
    142145   
  • branches/czw_branch/20110406/ippTools/src/addtoolConfig.c

    r31434 r31606  
    5656    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by camRun label", NULL);
    5757    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-data_group", PS_META_DUPLICATE_OK, "search by camRun data_group", NULL);
     58    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-filter", PS_META_DUPLICATE_OK, "search by filter", NULL);
    5859    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-reduction",          0, "search by camRun reduction class", NULL);
    5960    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-destreaked",           0, "only queue destreaked runs", false);
  • branches/czw_branch/20110406/ippTools/src/disttool.c

    r30906 r31606  
    447447
    448448    if (pretend) {
    449         if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) {
     449        if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", !simple)) {
    450450            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    451451            psFree(output);
  • branches/czw_branch/20110406/ippTools/src/magictool.c

    r31434 r31606  
    404404    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    405405    PXOPT_LOOKUP_BOOL(clearfault, config->args, "-clearfault", false);
    406 
     406    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     407   
    407408    psString setString = NULL;
    408409    if (fault || clearfault) {
     
    411412    if (note) {
    412413        psStringAppend(&setString, ", note = '%s'", note);
     414    }
     415    if (label) {
     416        psStringAppend(&setString, ", label = '%s'", label);
    413417    }
    414418
  • branches/czw_branch/20110406/ippTools/src/magictoolConfig.c

    r30497 r31606  
    8181    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "set state (required)", NULL);
    8282    psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-set_fault", 0, "set fault code", 0);
     83    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0, "define label", 0);
    8384    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_note",  0, "define note", NULL);
    8485    psMetadataAddBool(updaterunArgs, PS_LIST_TAIL, "-clearfault",  0, "set fault to zero", NULL);
  • branches/czw_branch/20110406/ippTools/src/pstamptool.c

    r30543 r31606  
    843843    psFree(where);
    844844
    845     psStringAppend(&query, " ORDER BY priority DESC, req_id");
     845    psStringAppend(&query, " ORDER BY priority DESC, req_id, job_id");
    846846
    847847    // treat limit == 0 as "no limit"
     
    13231323    psFree(where);
    13241324
    1325     psStringAppend(&query, " ORDER BY priority DESC, req_id");
     1325    psStringAppend(&query, " ORDER BY priority DESC, req_id, dep_id");
    13261326
    13271327    // treat limit == 0 as "no limit"
  • branches/czw_branch/20110406/ippTools/src/pubtoolConfig.c

    r30769 r31606  
    4848    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-product", 0, "define product (required)", NULL);
    4949    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-workdir", 0, "define workdir (required)", NULL);
     50    psMetadataAddS16(defineclientArgs, PS_LIST_TAIL, "-output_format", 0, "define output format", 2);
    5051    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-comment", 0, "define comment", NULL);
     52    psMetadataAddStr(defineclientArgs, PS_LIST_TAIL, "-name", 0, "define name", NULL);
    5153    psMetadataAddBool(defineclientArgs, PS_LIST_TAIL, "-unmagicked", 0, "allow unmagicked data?", false);
    5254
  • branches/czw_branch/20110406/ippTools/src/pzgetimfiles.c

    r31038 r31606  
    125125    if (status != 0) {
    126126        // mark the summitExp row as faulted
    127         if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %ld", WEXITSTATUS(status), summit_id)) {
     127        if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %lld", WEXITSTATUS(status), (long long) summit_id)) {
    128128            psError(PS_ERR_UNKNOWN, false, "database error");
    129129        }
     
    141141        // download an "empty" fileset.
    142142        // mark the summitExp row as faulted
    143         if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %ld", 250, summit_id)) {
     143        if (!p_psDBRunQueryF(config->dbh, "UPDATE summitExp SET fault = %d WHERE summit_id = %lld", 250, (long long) summit_id)) {
    144144                psError(PS_ERR_UNKNOWN, false, "database error");
    145145        }
  • branches/czw_branch/20110406/ippTools/src/pztool.c

    r31051 r31606  
    638638    // set pzDownloadExp.state to 'stop'
    639639    if (!pzDownloadExpSetState(config, summit_id, "stop")) {
    640         psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %ld", summit_id);
     640        psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %lld", (long long) summit_id);
    641641        return false;
    642642    }
     
    913913    char *query = "UPDATE pzDownloadExp SET state = '%s' WHERE summit_id = %ld";
    914914    if (!p_psDBRunQueryF(config->dbh, query, state, summit_id)) {
    915         psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
     915        psError(PS_ERR_UNKNOWN, false, "failed to change state for %lld", (long long) summit_id);
    916916        return false;
    917917    }
     
    927927
    928928  if (!pzDownloadExpSetState(config,summit_id, state)) {
    929     psError(PS_ERR_UNKNOWN, false, "failed to change state for %ld", summit_id);
     929    psError(PS_ERR_UNKNOWN, false, "failed to change state for %lld", (long long) summit_id);
    930930    return false;
    931931  }
  • branches/czw_branch/20110406/ippTools/src/stacktool.c

    r31253 r31606  
    246246    PXOPT_COPY_STR(config->args,  where, "-select_data_group",         "warpRun.data_group", "==");
    247247    pxAddLabelSearchArgs (config, where, "-select_label",              "warpRun.label", "LIKE"); // define using warp label
    248 
     248    pxAddLabelSearchArgs (config, where, "-warp_id",                   "warpRun.warp_id", "==");
     249   
    249250    // these are used to build the HAVING restriction
    250251    PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">=");
     
    487488        // Define the requested association, and insert it if it doesn't already exist
    488489        stackAssociationRow *association = pxStackAssociationDefine(config,stack_id);
    489         psS64 sass_id;
     490        psS64 sass_id=-1;
    490491        if (!association->sass_id) {
    491492          psTrace("stacktool.association",2,"No required Association found. Adding.");
     
    508509          association->sass_id = sass_id;
    509510        }
     511        else {
     512          sass_id = association->sass_id;
     513        }
    510514        // Insert the map entry for this row.
    511515        stackAssociationMapRow *maprow = stackAssociationMapRowAlloc(sass_id,stack_id);
  • branches/czw_branch/20110406/ippTools/src/stacktoolConfig.c

    r30945 r31606  
    9191    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_zpt_obs_max", 0, "define max zero point", NAN);
    9292    psMetadataAddF64(definebyqueryArgs, PS_LIST_TAIL, "-select_astrom", 0, "define max astrometry rms", NAN);
     93    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-warp_id", PS_META_DUPLICATE_OK, "include this warp ID (multiple OK)", 0);
    9394    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-random", 0, "use this number of random elements", 0);
    9495    psMetadataAddS32(definebyqueryArgs, PS_LIST_TAIL, "-min_num", 0, "minimum number of inputs", 0);
  • branches/czw_branch/20110406/ippconfig

  • branches/czw_branch/20110406/ippconfig/gpc1/camera.config

    r31163 r31606  
    165165NPIX_INTERCHIP          S32     103794483
    166166
     167# This sets the maximum size for the fwhm_major.  This is roughly 3", and 98.67% of all exposures in the database are less than this.
     168MAX_ALLOWED_FWHM          F32         12
     169
    167170# The set of maskbits that should not be set to NAN in "released" images
    168171# This value is equal to CONV.POOR | STARCORE | SPIKE | SUSPECT  = 0x5280
  • branches/czw_branch/20110406/ippconfig/gpc1/ppStack.config

    r31163 r31606  
    3535
    3636STACK_THREEPI  METADATA
     37    PSF.INPUT.MAX   F32     12.0
    3738    OUTPUT.NOCOMP   BOOL    FALSE
    3839    OUTPUT.LOGFLUX  BOOL    TRUE
  • branches/czw_branch/20110406/ippconfig/gpc1/psastro.config

    r31434 r31606  
    113113
    114114# *** make sure the choice of CATDIR (dvo database) contains the photcodes desired below
    115 PSASTRO.CATDIR              STR      SYNTH.GRIZY
     115PSASTRO.CATDIR              STR      SYNTH.GRIZY 
    116116DVO.GETSTAR.PHOTCODE        STR      i
    117117DVO.GETSTAR.MAX.RHO         F32      3000.0
     
    129129  FILTER   STR g
    130130  ZEROPT   F32 24.9
    131   PHOTCODE STR g_SYNTH
     131  PHOTCODE STR g
    132132  GHOST_MAX_MAG                   F32 -20.0
    133133END
     
    135135  FILTER   STR r
    136136  ZEROPT   F32 25.1
    137   PHOTCODE STR r_SYNTH
     137  PHOTCODE STR r
    138138  GHOST_MAX_MAG                   F32 -20.0
    139139END
     
    141141  FILTER   STR i
    142142  ZEROPT   F32 25.0
    143   PHOTCODE STR i_SYNTH
     143  PHOTCODE STR i
    144144  GHOST_MAX_MAG                   F32 -25.0
    145145END
     
    147147  FILTER   STR z
    148148  ZEROPT   F32 24.6
    149   PHOTCODE STR z_SYNTH
     149  PHOTCODE STR z
    150150  GHOST_MAX_MAG                   F32 -25.0
    151151END
     
    153153  FILTER   STR y
    154154  ZEROPT   F32 22.2
    155   PHOTCODE STR y_SYNTH
     155  PHOTCODE STR y
    156156  GHOST_MAX_MAG                   F32 -25.0
    157157END
     
    159159  FILTER   STR w
    160160  ZEROPT   F32 26.3
    161   PHOTCODE STR r_SYNTH
     161  PHOTCODE STR r
    162162  GHOST_MAX_MAG                   F32 -20.0
    163163END
     
    345345  PSASTRO.MATCH.FIT.NITER S32    5
    346346END
     347
     348LAP_ASTRO METADATA
     349  PSASTRO.CATDIR                STR      3PI.20110505.REFCAT
     350END
  • branches/czw_branch/20110406/ippconfig/gpc1/psphot.config

    r31163 r31606  
    2020PSF_MODEL                           STR   PS_MODEL_PS1_V1
    2121PSPHOT.CR.NSIGMA.SOFTEN             F32   0.0025        # Softening parameter for weights in CR stat
     22
     23PSPHOT.CR.MAX.SIZE                  F32   0.8             # guess for limit on M_minor in pix^2
     24PSPHOT.CR.MAX.MAG                   F32  -8.0             # guess for limit on Kron Mag
     25PSPHOT.CR.AUTOSCALE                 BOOL  FALSE
    2226
    2327PSF.TREND.NX                        S32   3
  • branches/czw_branch/20110406/ippconfig/isp/psastro.config

    r27289 r31606  
    33
    44# nominal plate scale (microns / pixel)
    5 PSASTRO.PIXEL.SCALE    F32  10.0
     5PSASTRO.PIXEL.SCALE    F32  1.0
    66
    77# pmAstromGridMatch:
    88PSASTRO.GRID.MIN.ANGLE F32 -2.0
    99PSASTRO.GRID.MAX.ANGLE F32 +2.0
    10 PSASTRO.GRID.DEL.ANGLE F32  0.25
     10PSASTRO.GRID.DEL.ANGLE F32  0.5
    1111PSASTRO.GRID.MIN.SIGMA F32  5.0
    1212
     
    1414# max grid offset in FP units (microns)
    1515# use plate-scale to make this in pixels?
    16 PSASTRO.GRID.OFFSET    F32   10000.
    17 PSASTRO.GRID.SCALE     F32     500
     16PSASTRO.GRID.OFFSET    F32   500.
     17PSASTRO.GRID.SCALE     F32      10
    1818
     19PSASTRO.GRID.NREF.MAX S32 2500
     20PSASTRO.GRID.NRAW.MAX S32 1500
     21
     22PSASTRO.PLOT.INST.MAG.MAX F32 -4.0
     23PSASTRO.PLOT.INST.MAG.MIN F32 -12.0
     24PSASTRO.PLOT.REF.MAG.MIN  F32 +10.0
     25PSASTRO.PLOT.REF.MAG.MAX  F32 +20.0
     26
     27PSASTRO.MIN.INST.MAG.RAW      F32  -12
     28PSASTRO.GRID.MIN.INST.MAG.RAW F32  -12
     29PSASTRO.MAX.INST.MAG.RAW      F32  -4
     30PSASTRO.GRID.MAX.INST.MAG.RAW F32  -4
     31
     32 #PSASTRO.MATCH.RADIUS   F32    3
     33
     34PSASTRO.MATCH.RADIUS.N0 F32    15
     35PSASTRO.MATCH.RADIUS.N1 F32    10
     36PSASTRO.MATCH.RADIUS.N2 F32    9
     37PSASTRO.MATCH.RADIUS.N3 F32    8
     38PSASTRO.MATCH.RADIUS.N4 F32    7
     39PSASTRO.MATCH.RADIUS.N5 F32    5
     40PSASTRO.MATCH.RADIUS.N6 F32    5
     41PSASTRO.MATCH.RADIUS.N7 F32    3
     42
     43PSASTRO.MATCH.FIT.NITER S32    8
    1944# these tweak are in FP units (pixels, currently)
    2045PSASTRO.TWEAK.SCALE     F32      1
     
    2449
    2550# match radius in pixels for CHIP astrometry
    26 PSASTRO.MATCH.RADIUS   F32    8
     51PSASTRO.MATCH.RADIUS   F32    5
    2752
    2853# pmAstromMatchFit
     
    3863PSASTRO.CATDIR         STR      SYNTH.BRIGHT
    3964PSASTRO.MATCH.LUMFUNC  BOOL     TRUE
     65PSASTRO.IGNORE         STR      SATURATED, DEFECT, SATSTAR, BLEND,FAIL
     66
     67
    4068
    4169
  • branches/czw_branch/20110406/ippconfig/isp/psphot.config

    r25756 r31606  
     1# cosmic ray recipe options - these were tested with o5472i0009o01.201734.ch.191131.cmf
     2
     3PSPHOT.CR.MAX.SIZE                  F32   0.20           # guess for limit on M_minor in pix^2
     4PSPHOT.CR.MAX.MAG                   F32   -7.0             # guess for limit on Kron Mag
     5PSPHOT.CR.AUTOSCALE                 BOOL  FALSE
     6
    17
    28# turn these on to see specific outputs
  • branches/czw_branch/20110406/ippconfig/recipes/nightly_science.config

    r31434 r31606  
    203203  NAME      STR STS
    204204  DISTRIBUTION STR STS
    205   # XXX: STS observations are temporarily being taken outside the STS tessellation
    206   # switch tess_id from STS.V3 to RINGS
    207   TESS      STR RINGS.V3
    208   # TESS      STR STS.V3
     205  TESS      STR STS.V4
    209206  OBSMODE   STR STS%
    210   OBJECT    STR STS%
     207#  OBJECT    STR STS%
    211208  STACKABLE BOOL FALSE
    212209  DIFFABLE  BOOL FALSE
    213210  REDUCTION STR STS_DATASET
     211  # bump the retention times for the time being
     212  CHIP S16 60
     213  WARP S16 60
     214  DIFF S16 60
    214215END
    215216TARGETS METADATA
  • branches/czw_branch/20110406/ippconfig/recipes/psastro.config

    r31434 r31606  
    250250STS_DATASET METADATA
    251251END
     252
     253LAP_ASTRO METADATA
     254 
     255END
     256
  • branches/czw_branch/20110406/ippconfig/recipes/psphot.config

    r31434 r31606  
    318318PSPHOT.CRMASK.YTEST                 S32   0
    319319PSPHOT.CRMASK.APPLY                 BOOL  FALSE           # TEST THIS before enabling.
    320 PSPHOT.CR.MAX.SIZE                  F32   0.8             # guess for limit on M_minor in pix^2
    321 PSPHOT.CR.MAX.MAG                   F32  -8.0             # guess for limit on Kron Mag
     320PSPHOT.CR.MAX.SIZE                  F32   0               # guess for limit on M_minor in pix^2
     321PSPHOT.CR.MAX.MAG                   F32   0               # guess for limit on Kron Mag
    322322PSPHOT.CR.AUTOSCALE                 BOOL  FALSE
    323323
     
    377377END
    378378
     379# Extended source fit parameters
     380STACKPHOT_TEST_V1                     METADATA
     381  EXTENDED_SOURCE_FITS                BOOL  F  # perform any of the aperture-like measurements?
     382  EXTENDED_SOURCE_ANALYSIS            BOOL  F  # perform any of the aperture-like measurements?
     383  EXTENDED_SOURCE_SN_LIM              F32   20.0
     384  EXTENDED_SOURCE_PETROSIAN           BOOL  TRUE
     385  EXTENDED_SOURCE_ANNULI              BOOL  TRUE
     386  PSPHOT.STACK.MATCH.PSF.SOURCE       STR   AUTO # which inputs to convolve? (RAW, CNV, AUTO)
     387  PSPHOT.STACK.TARGET.PSF.AUTO        BOOL  F    # automatically determine target PSF size?
     388  PSPHOT.STACK.USE.RAW                BOOL  F    # perform photometry & morphology analysis on the raw image
     389  @PSPHOT.STACK.TARGET.PSF.FWHM       F32   8.0 10.0 # FWHM of target PSF (if NOT AUTO sized; pixels)
     390  RADIAL_APERTURES                    BOOL  F    # calculate flux in circular radial apertures?
     391  RADIAL_APERTURES_SN_LIM             F32   0.0  # S/N limit for radial aperture calculation
     392  OUTPUT.FORMAT                       STR   PS1_V3
     393
     394  CONSTANT_PHOTOMETRIC_WEIGHTS        BOOL  TRUE
     395  POISSON.ERRORS.PHOT.LMM             BOOL  FALSE
     396  PSF_APERTURE_SCALE                  F32   4.5
     397  PSF_REF_RADIUS                      F32   35
     398
     399  EXT_FIT_MAX_RADIUS                  F32   50.0
     400  PSF_MODEL                           STR   PS_MODEL_QGAUSS
     401  EXT_MODEL                           STR   PS_MODEL_SERSIC
     402END
     403
     404# Extended source fit parameters
     405SINGLE_TEST_V1                     METADATA
     406  EXTENDED_SOURCE_FITS                BOOL  F  # perform any of the aperture-like measurements?
     407  EXTENDED_SOURCE_ANALYSIS            BOOL  F  # perform any of the aperture-like measurements?
     408  EXTENDED_SOURCE_SN_LIM              F32   20.0
     409  EXTENDED_SOURCE_PETROSIAN           BOOL  TRUE
     410  EXTENDED_SOURCE_ANNULI              BOOL  TRUE
     411  PSPHOT.STACK.MATCH.PSF.SOURCE       STR   AUTO # which inputs to convolve? (RAW, CNV, AUTO)
     412  PSPHOT.STACK.TARGET.PSF.AUTO        BOOL  F    # automatically determine target PSF size?
     413  PSPHOT.STACK.USE.RAW                BOOL  F    # perform photometry & morphology analysis on the raw image
     414  @PSPHOT.STACK.TARGET.PSF.FWHM       F32   8.0 10.0 # FWHM of target PSF (if NOT AUTO sized; pixels)
     415  RADIAL_APERTURES                    BOOL  T    # calculate flux in circular radial apertures?
     416  RADIAL_APERTURES_SN_LIM             F32   0.0  # S/N limit for radial aperture calculation
     417  OUTPUT.FORMAT                       STR   PS1_SV1
     418 #  OUTPUT.FORMAT                       STR   PS1_V3
     419
     420  # CONSTANT_PHOTOMETRIC_WEIGHTS        BOOL  TRUE
     421  # POISSON.ERRORS.PHOT.LMM             BOOL  FALSE
     422  CONSTANT_PHOTOMETRIC_WEIGHTS        BOOL  FALSE
     423  POISSON.ERRORS.PHOT.LMM             BOOL  TRUE
     424
     425  PSF_APERTURE_SCALE                  F32   4.5
     426  PSF_REF_RADIUS                      F32   35
     427
     428  EXT_FIT_MAX_RADIUS                  F32   50.0
     429  PSF_MODEL                           STR   PS_MODEL_PS1_V1
     430  EXT_MODEL                           STR   PS_MODEL_SERSIC
     431END
     432
    379433STACKPHOT_SINGLE    METADATA
    380434  PSPHOT.STACK.USE.RAW                BOOL  F   # since false perform photometry & morphology analysis on the convolved images
  • branches/czw_branch/20110406/ippconfig/recipes/reductionClasses.mdc

    r31434 r31606  
    165165END
    166166
     167# large area science analysis
     168LAP_SCIENCE             METADATA
     169        CHIP_PPIMAGE      STR     CHIP
     170        CHIP_PSPHOT       STR     CHIP
     171        WARP_PSWARP       STR     WARP
     172        STACK_PPSTACK     STR     STACK
     173        STACK_PPSUB       STR     STACK
     174        STACK_PSPHOT      STR     STACK
     175        DIFF_PPSUB        STR     DIFF
     176        DIFF_PSPHOT       STR     DIFF
     177        JPEG_BIN1         STR     PPIMAGE_J1
     178        JPEG_BIN2         STR     PPIMAGE_J2
     179        FAKEPHOT          STR     FAKEPHOT
     180        ADDSTAR           STR     ADDSTAR
     181        PSASTRO           STR     LAP_ASTRO
     182        STACKPHOT_PSPHOT  STR     STACKPHOT
     183        STACKPHOT_PPSUB   STR     STACKPHOT
     184        STACKPHOT_PPSTACK STR     STACKPHOT
     185        STACKPHOT_SINGLE_PSPHOT  STR     STACKPHOT_SINGLE
     186        BACKGROUND_PPBACKGROUND STR     BACKGROUND
     187        BACKGROUND_PSWARP       STR     BACKGROUND
     188END
     189
    167190DEFAULT_MASKTEST                METADATA
    168191        CHIP_PPIMAGE    STR     CHIP_MASKTEST
  • branches/czw_branch/20110406/ppImage/src

  • branches/czw_branch/20110406/ppSim/src/ppSimInsertGalaxies.c

    r29002 r31606  
    162162        source->psfMag = -2.5*log10(galaxy->flux);
    163163        source->extMag = -2.5*log10(galaxy->flux);
    164         source->errMag = sqrt(Area*PS_SQR(roughNoise) + galaxy->flux) / galaxy->flux;   
     164        source->psfMagErr = sqrt(Area*PS_SQR(roughNoise) + galaxy->flux) / galaxy->flux;       
    165165       
    166166        // insert the source flux in the image
     
    173173
    174174        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
    175         fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", galaxy->x, galaxy->y, flux, 1, source->psfMag, source->errMag, axes.major, axes.minor, axes.theta, par8);
     175        fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", galaxy->x, galaxy->y, flux, 1, source->psfMag, source->psfMagErr, axes.major, axes.minor, axes.theta, par8);
    176176
    177177        psArrayAdd (sources, 100,source);
  • branches/czw_branch/20110406/ppSim/src/ppSimInsertStars.c

    r29002 r31606  
    121121
    122122        source->psfMag = -2.5*log10(star->flux);
    123         source->errMag = sqrt(Area*PS_SQR(roughNoise) + flux) / flux;
     123        source->psfMagErr = sqrt(Area*PS_SQR(roughNoise) + flux) / flux;
    124124       
    125125        // set the expected model errors
    126         model->dparams->data.F32[PM_PAR_I0] = source->errMag * model->params->data.F32[PM_PAR_I0];
     126        model->dparams->data.F32[PM_PAR_I0] = source->psfMagErr * model->params->data.F32[PM_PAR_I0];
    127127
    128128        float par8 = (model->params->n == 8) ? model->params->data.F32[7] : 0.0;
    129         fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", star->x, star->y, star->flux, 0, source->psfMag, source->errMag, axes.major, axes.minor, axes.theta, par8);
     129        fprintf (outfile, "%8.3f %8.3f %10.2f  %2d  %7.3f %5.3f  %5.3f %5.3f %5.3f %5.3f\n", star->x, star->y, star->flux, 0, source->psfMag, source->psfMagErr, axes.major, axes.minor, axes.theta, par8);
    130130
    131131        // if psfConvolve is TRUE, we will (elsewhere) convolve the image we a PSF
  • branches/czw_branch/20110406/ppStack/src/ppStackPrepare.c

    r31158 r31606  
    144144    int numCols = 0, numRows = 0;   // Size of image
    145145    options->sumExposure = 0.0;
     146    int numWithSources = 0;
    146147    for (int i = 0; i < num; i++) {
    147148        pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File of interest
     
    188189            pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout with sources
    189190            detections = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.DETECTIONS"); // Sources
    190             if (!detections || !detections->allSources) {
     191            if (!detections || !detections->allSources || !detections->allSources->n) {
    191192                psWarning("No detections found for image %d --- rejecting.", i);
    192193                options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PPSTACK_MASK_CAL;
     
    196197
    197198            options->sourceLists->data[i] = psMemIncrRefCounter(detections->allSources);
     199            numWithSources++;
    198200        }
    199201
     
    230232            ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
    231233        }
     234    }
     235    if (numWithSources < 2) {
     236        // This can happen if the inputs have been destreaked
     237        psErrorStackPrint(stderr, "Not enough inputs have sources");
     238        psWarning("No inputs have sources --- suspect bad data quality.");
     239        if (options->quality == 0) {
     240            options->quality = PPSTACK_ERR_DATA;
     241        }
     242        psErrorClear();
     243        psFree(view);
     244        return false;
    232245    }
    233246
     
    308321        psFree(psfs);
    309322        if (!options->psf) {
     323#if 1
    310324            psError(psErrorCodeLast(), false, "Unable to determine output PSF.");
     325#else
     326            // This will repair the problem reproted in ticket 1427 but we aren't yet sure
     327            // why ppStackPSF is failing so we are going to continue to fault for now
     328            int errorCode = psErrorCodeLast();
     329            if (errorCode == PPSTACK_ERR_PSF) {
     330                psErrorStackPrint(stderr, "Unable to determine output PSF.");
     331                psWarning("Unable to determine output PSF --- suspect bad data quality.");
     332                if (options->quality == 0) {
     333                    options->quality = errorCode;
     334                }
     335                psErrorClear();
     336            } else {
     337                psError(psErrorCodeLast(), false, "Unable to determine output PSF.");
     338            }
     339#endif // notyet
    311340            psFree(view);
    312341            return false;
  • branches/czw_branch/20110406/ppSub/src/ppSubFlagNeighbors.c

    r31156 r31606  
    112112                  bool positive = !matchRef && (sourceM1->imageID == 1);
    113113                  positive |= matchRef && (sourceM1->imageID == 2);
    114                   float SN1 = isfinite(sourceM1->errMag) ? 1.0 / sourceM1->errMag : NAN;
     114                  float SN1 = isfinite(sourceM1->psfMagErr) ? 1.0 / sourceM1->psfMagErr : NAN;
    115115                  if (positive) {
    116116                      source->diffStats->SNp = SN1;
     
    138138                  bool positive = !matchRef && (sourceM1->imageID == 1);
    139139                  positive |= matchRef && (sourceM1->imageID == 2);
    140                   float SN1 = isfinite(sourceM1->errMag) ? 1.0 / sourceM1->errMag : NAN;
    141                   float SN2 = isfinite(sourceM2->errMag) ? 1.0 / sourceM2->errMag : NAN;
     140                  float SN1 = isfinite(sourceM1->psfMagErr) ? 1.0 / sourceM1->psfMagErr : NAN;
     141                  float SN2 = isfinite(sourceM2->psfMagErr) ? 1.0 / sourceM2->psfMagErr : NAN;
    142142                  if (positive) {
    143143                      source->diffStats->SNp = SN1;
  • branches/czw_branch/20110406/ppSub/src/ppSubReadoutPhotometry.c

    r31302 r31606  
    176176
    177177            fprintf(sourceFile, "%f %f %f %f %f %f %f %f %d %f %f %f %f %f\n",
    178                     x, y, source->psfMag, source->errMag, chi2, source->crNsigma, source->extNsigma,
     178                    x, y, source->psfMag, source->psfMagErr, chi2, source->crNsigma, source->extNsigma,
    179179                    source->pixWeight, source->mode, xMoment, yMoment, xxMoment, xyMoment, yyMoment);
    180180        }
  • branches/czw_branch/20110406/psLib/src/fits/psFitsImage.c

    r30636 r31606  
    485485      double boffset;
    486486      int status;
     487      status = 0;
    487488      fits_read_key_dbl(fits->fd, "BOFFSET", &boffset, NULL, &status);
    488       outImage = psFitsScaleFromDisk(outImage,boffset);
     489      psImage *newImage = psFitsScaleFromDisk(outImage,boffset);
     490      psFree (outImage);
     491      outImage = newImage;
    489492    }
    490493    psFree(info);
  • branches/czw_branch/20110406/psLib/src/imageops/psImageGeomManip.c

    r23989 r31606  
    702702    } \
    703703    /* note: output(i,j) = input(i+0.5-dx,j+0.5-dy) */ \
    704     /* positive dx,dy moves pixel i-dx,j-dy to i,y */ \
     704    /* positive dx,dy moves pixel i-dx,j-dy to i,j */ \
    705705    /* also: pixel center is 0.5,0.5 */ \
    706706    for (int row = 0; row < numRows; row++) { \
  • branches/czw_branch/20110406/psLib/src/imageops/psImageInterpolate.c

    r28667 r31606  
    3131#include "psImageConvolve.h"
    3232
     33# define IS_BILIN_SEPARABLE 0
     34
    3335#include "psImageInterpolate.h"
    3436
     
    4850};
    4951
     52# if (IS_BILIN_SEPARABLE)
    5053/// Generate a linear interpolation kernel
    5154static inline void interpolationKernelBilinear(psF32 *kernel, // Kernel vector to populate
     
    5659    kernel[1] = frac;
    5760}
     61# else
     62/// Generate a linear interpolation kernel
     63static inline void interpolationKernelBilinear(
     64    psF32 kernel[kernelSizes[PS_INTERPOLATE_BILINEAR]][kernelSizes[PS_INTERPOLATE_BILINEAR]], // Kernel
     65    float xFrac, float yFrac // Fraction of pixel
     66    )
     67{
     68    // (xF*yF, (1-xF)(1-yF) = 1 - xF - yF + xFyF
     69
     70    kernel[0][0] = 1.0 - xFrac - yFrac + xFrac*yFrac;
     71    kernel[1][0] = yFrac - xFrac*yFrac;
     72    kernel[0][1] = xFrac - xFrac*yFrac;
     73    kernel[1][1] = xFrac*yFrac;
     74}
     75# endif
    5876
    5977#if 0
     
    173191        // Nothing to pre-compute
    174192        break;
     193# if (IS_BILIN_SEPARABLE)
    175194      case PS_INTERPOLATE_BILINEAR:
    176195        interpolationKernelBilinear(kernel, frac);
    177196        break;
     197# endif
    178198      case PS_INTERPOLATE_GAUSS:
    179199        interpolationKernelGauss(kernel, kernelSizes[mode], 0.5, frac);
     
    184204        interpolationKernelLanczos(kernel, kernelSizes[mode], frac);
    185205        break;
     206# if (!IS_BILIN_SEPARABLE)
     207      case PS_INTERPOLATE_BILINEAR:
     208# endif
    186209      case PS_INTERPOLATE_BIQUADRATIC:  // 2D kernel
    187210      default:
     
    234257
    235258    switch (mode) {
     259# if (IS_BILIN_SEPARABLE)
    236260      case PS_INTERPOLATE_BILINEAR:
     261# endif
    237262      case PS_INTERPOLATE_GAUSS:
    238263      case PS_INTERPOLATE_LANCZOS2:
     
    258283        }
    259284        break;
     285# if (!IS_BILIN_SEPARABLE)
     286      case PS_INTERPOLATE_BILINEAR:
     287# endif
    260288      case PS_INTERPOLATE_BIQUADRATIC:
    261289        // 2D kernel, would cost too much memory to pre-calculate
     
    360388    int xCentral = floor((X) - 0.5), yCentral = floor((Y) - 0.5); /* Central pixel */ \
    361389    float xFrac = (X) - xCentral - 0.5, yFrac = (Y) - yCentral - 0.5; /* Fraction of pixel */ \
     390    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
     391
     392// Set up the kernel parameters; defines some useful values
     393// EAM : I'm unsure of the right answer here
     394#define INTERPOLATE_SETUP_EAM(X, Y)                              \
     395    int xCentral = floor((X)), yCentral = floor((Y)); /* Central pixel */ \
     396    float xFrac = (X) - xCentral, yFrac = (Y) - yCentral; /* Fraction of pixel */ \
    362397    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
    363398
     
    722757}
    723758
    724 // Interpolation engine for (separable) interpolation kernels
     759// Interpolation engine for (non-separable) interpolation kernels
    725760static psImageInterpolateStatus interpolateKernel(double *imageValue, double *varianceValue,
    726761                                                  psImageMaskType *maskValue, float x, float y,
     
    747782    // Get the appropriate kernels
    748783    psF32 kernel[size][size];
     784
     785# if (IS_BILIN_SEPARABLE)
    749786    psAssert(mode == PS_INTERPOLATE_BIQUADRATIC, "Mode is %x", mode);
    750787    interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     788# else
     789    psAssert((mode == PS_INTERPOLATE_BIQUADRATIC) || (mode == PS_INTERPOLATE_BILINEAR), "Mode is %x", mode);
     790    if (mode == PS_INTERPOLATE_BIQUADRATIC) {
     791        interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     792    } else {
     793        interpolationKernelBilinear(kernel, xFrac, yFrac);
     794    }
     795# endif
     796
     797# if (0)
     798    for (int i = 0; i < size; i++) {
     799        for (int j = 0; j < size; j++) {
     800            fprintf (stderr, "%f ", kernel[i][j]);
     801        }
     802        fprintf (stderr, "\n");
     803    }
     804# endif
    751805
    752806    float sumKernel = 0.0;              // Sum of the kernel
     
    908962        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
    909963      case PS_INTERPOLATE_BILINEAR:
     964# if (!IS_BILIN_SEPARABLE)
     965        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
     966# endif
    910967      case PS_INTERPOLATE_GAUSS:
    911968      case PS_INTERPOLATE_LANCZOS2:
  • branches/czw_branch/20110406/psLib/src/imageops/psImageMaskOps.c

    r25753 r31606  
    146146    for (int iy = 0; iy < image->numRows; iy++) { \
    147147        for (int ix = 0; ix < image->numCols; ix++) { \
    148             dx = ix + image->col0 - x; \
    149             dy = iy + image->row0 - y; \
     148            dx = ix + 0.5 + image->col0 - x; \
     149            dy = iy + 0.5 + image->row0 - y; \
    150150            r2 = PS_SQR(dx) + PS_SQR(dy); \
    151151            if (r2 <= R2) { \
     
    197197    for (int iy = 0; iy < image->numRows; iy++) { \
    198198        for (int ix = 0; ix < image->numCols; ix++) { \
    199             dx = ix + image->col0 - x; \
    200             dy = iy + image->row0 - y; \
     199            dx = ix + 0.5 + image->col0 - x; \
     200            dy = iy + 0.5 + image->row0 - y; \
    201201            r2 = PS_SQR(dx) + PS_SQR(dy); \
    202202            if (r2 > R2) { \
  • branches/czw_branch/20110406/psModules/src/camera/pmFPAMaskWeight.c

    r29544 r31606  
    587587                double imageValue, varianceValue; // Image and variance value from interpolation
    588588                psImageMaskType maskValue = 0; // Mask value from interpolation
    589                 psImageInterpolateStatus status = psImageInterpolate(&imageValue, &varianceValue, &maskValue, x, y, interp);
     589
     590                // interpolate to pixel center (index + 0.5)
     591                psImageInterpolateStatus status = psImageInterpolate(&imageValue, &varianceValue, &maskValue, x + 0.5, y + 0.5, interp);
    590592                if (status == PS_INTERPOLATE_STATUS_ERROR || status == PS_INTERPOLATE_STATUS_OFF) {
    591593                    psError(PS_ERR_UNKNOWN, false, "Unable to interpolate readout at %d,%d", x, y);
  • branches/czw_branch/20110406/psModules/src/imcombine/pmPSFEnvelope.c

    r29543 r31606  
    380380
    381381        // measure the source moments: tophat windowing, no pixel S/N cutoff
    382         if (!pmSourceMoments(source, maxRadius, 0.0, 0.0, maskVal)) {
     382        if (!pmSourceMoments(source, maxRadius, 0.0, 0.0, 0.0, maskVal)) {
    383383            // Can't do anything about it; limp along as best we can
    384384            psErrorClear();
  • branches/czw_branch/20110406/psModules/src/imcombine/pmSubtractionStamps.c

    r31153 r31606  
    834834            }
    835835
    836             psStatsInit (stats);
    837             if (!psVectorStats (stats, flux1, NULL, NULL, 0)) {
    838                 psAbort ("failed to generate stats");
    839             }
    840             float f1 = stats->sampleMedian;
    841 
    842             psStatsInit (stats);
    843             if (!psVectorStats (stats, flux2, NULL, NULL, 0)) {
    844                 psAbort ("failed to generate stats");
    845             }
    846             float f2 = stats->sampleMedian;
     836            float f1 = NAN;
     837            if (flux1->n > 0) {
     838                psStatsInit (stats);
     839                if (!psVectorStats (stats, flux1, NULL, NULL, 0)) {
     840                    psAbort ("failed to generate stats");
     841                }
     842                f1 = stats->sampleMedian;
     843            }
     844
     845            float f2 = NAN;
     846            if (flux2->n > 0) {
     847                psStatsInit (stats);
     848                if (!psVectorStats (stats, flux2, NULL, NULL, 0)) {
     849                    psAbort ("failed to generate stats");
     850                }
     851                f2 = stats->sampleMedian;
     852            }
    847853
    848854            stamps->window1->kernel[y][x] = f1;
     
    893899    float R2 = Sr2 / Sf2;
    894900
     901    if (!isfinite(R1) || !isfinite(R2)) {
     902        psError(PM_ERR_STAMPS, true, "Kron Radii are not finite (failure to converge).");
     903        psFree (stats);
     904        psFree (flux1);
     905        psFree (flux2);
     906        psFree (norm1);
     907        psFree (norm2);
     908        return false;
     909    }
     910
    895911    // Compare the Kron Radii (R1 & R2) to above to the FWHMs : if they are too discrepant, we will need to rescale
    896912    psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Kron Radii vs FWHMs 1: fwhm: %f, kron %f\n", fwhm1, R1);
     
    901917    stamps->normWindow2 = 2.75*R2;
    902918    psLogMsg ("psModules.imcombine", PS_LOG_DETAIL, "Windows from Kron Radii: %f for 1, %f for 2\n", stamps->normWindow1, stamps->normWindow2);
     919
    903920
    904921    // if the calculated normWindows are too large, we will fall off the stamps.  In this case, we need to try again.
     
    913930        psFree (norm2);
    914931        return false;
    915     }
    916 
    917     if (!isfinite(R1) || !isfinite(R2)) {
    918         psError(PM_ERR_STAMPS, true, "Kron Radii are not finite (failure to converge).");
    919         psFree (stats);
    920         psFree (flux1);
    921         psFree (flux2);
    922         psFree (norm1);
    923         psFree (norm2);
    924         return false;
    925932    }
    926933
     
    11971204       
    11981205        // fprintf (stderr, "%f,%f : %f %f : %f %f\n", source->peak->xf, source->peak->yf,
    1199         // source->psfMag, source->apMag, source->psfMag - source->apMag, source->errMag);
     1206        // source->psfMag, source->apMag, source->psfMag - source->apMag, source->psfMagErr);
    12001207
    12011208        // XXX this is somewhat arbitrary...
    1202         if (source->errMag > 0.05) continue;
     1209        if (source->psfMagErr > 0.05) continue;
    12031210        if (fabs(source->psfMag - source->apMag) > 0.5) continue;
    12041211
  • branches/czw_branch/20110406/psModules/src/objects/Makefile.am

    r31153 r31606  
    114114        pmTrend2D.h \
    115115        pmGrowthCurve.h \
     116        pmGrowthCurveGenerate.h \
    116117        pmSourceMatch.h \
    117118        pmDetEff.h \
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_DEV.c

    r31153 r31606  
    268268    float f0 = 1.0;
    269269    float f1, f2;
    270     for (z = DZ; z < 50; z += DZ) {
     270    for (z = DZ; z < 150; z += DZ) {
    271271        f1 = exp(-pow(z,ALPHA));
    272272        z += DZ;
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_EXP.c

    r31153 r31606  
    255255    float f0 = 1.0;
    256256    float f1, f2;
    257     for (z = DZ; z < 50; z += DZ) {
     257    for (z = DZ; z < 150; z += DZ) {
    258258        f1 = exp(-sqrt(z));
    259259        z += DZ;
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_PGAUSS.c

    r31153 r31606  
    239239    float f0 = 1.0;
    240240    float f1, f2;
    241     for (z = DZ; z < 50; z += DZ) {
     241    for (z = DZ; z < 150; z += DZ) {
    242242        f1 = 1.0 / (1 + z + z*z/2.0 + z*z*z/6.0);
    243243        z += DZ;
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_PS1_V1.c

    r31153 r31606  
    261261    float f0 = 1.0;
    262262    float f1, f2;
    263     for (z = DZ; z < 50; z += DZ) {
     263    for (z = DZ; z < 150; z += DZ) {
    264264        f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA));
    265265        z += DZ;
     
    288288    if (PAR[PM_PAR_I0] <= 0) return 1.0;
    289289    if (flux >= PAR[PM_PAR_I0]) return 1.0;
    290     if (PAR[PM_PAR_7] == 0.0) return powf(PAR[PM_PAR_I0] / flux - 1.0, 1.0 / ALPHA);
    291290
    292291    shape.sx  = PAR[PM_PAR_SXX] / M_SQRT2;
     
    296295    psEllipseAxes axes = psEllipseShapeToAxes (shape, 20.0);
    297296    psF64 sigma = axes.major;
     297
     298    if (PAR[PM_PAR_7] == 0.0) {
     299        psF32 z =  powf(PAR[PM_PAR_I0] / flux - 1.0, 1.0 / ALPHA);
     300        return ( sigma * sqrt (2.0 * z) );
     301    }
    298302
    299303    psF64 limit = flux / PAR[PM_PAR_I0];
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_QGAUSS.c

    r31153 r31606  
    262262    float f0 = 1.0;
    263263    float f1, f2;
    264     for (z = DZ; z < 50; z += DZ) {
     264    for (z = DZ; z < 150; z += DZ) {
    265265        f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, ALPHA));
    266266        z += DZ;
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_RGAUSS.c

    r31153 r31606  
    251251    float f0 = 1.0;
    252252    float f1, f2;
    253     for (z = DZ; z < 50; z += DZ) {
     253    for (z = DZ; z < 150; z += DZ) {
    254254        f1 = 1.0 / (1 + z + pow(z, PAR[PM_PAR_7]));
    255255        z += DZ;
  • branches/czw_branch/20110406/psModules/src/objects/models/pmModel_SERSIC.c

    r31153 r31606  
    316316    float f0 = 1.0;
    317317    float f1, f2;
    318     for (z = DZ; z < 50; z += DZ) {
     318    for (z = DZ; z < 150; z += DZ) {
    319319        // f1 = 1.0 / (1 + PAR[PM_PAR_7]*z + pow(z, 2.25));
    320320        f1 = exp(-pow(z,PAR[PM_PAR_7]));
  • branches/czw_branch/20110406/psModules/src/objects/pmGrowthCurve.c

    r29004 r31606  
    7373    // Fractional pixel radii are not well defined; use integer pixel radii.  Use 1 pixel steps
    7474    // until the scaling factor steps in intervals larger than 1 pixel
    75     float Rlin = 1.0 / (fR - 1.0);
     75    // float Rlin = 1.0 / (fR - 1.0);
    7676
    7777    growth->radius = psVectorAllocEmpty (NPTS, PS_DATA_F32);
     
    7979    // there will be NPTS radii + a few extras
    8080    float radius = minRadius;
    81     while (radius < Rlin) {
     81    while (radius < refRadius) {
    8282        // fprintf (stderr, "r: %f\n", radius);
    83         psVectorAppend (growth->radius, radius);
     83        psVectorAppend (growth->radius, radius - 0.001);
    8484        radius += 1.0;
    8585    }   
     86    growth->refBin = growth->radius->n - 1;
    8687    while (radius < maxRadius) {
    8788        // fprintf (stderr, "r: %f\n", radius);
    88         psVectorAppend (growth->radius, radius);
     89        psVectorAppend (growth->radius, radius - 0.001);
    8990        radius *= fR;
    9091        radius = (int) (radius + 0.5);
     
    9697    growth->refRadius = refRadius;
    9798    growth->maxRadius = maxRadius;
    98     growth->apLoss = 0.0;
    99     growth->fitMag = 0.0;
     99    growth->fitMag = NAN;
     100    growth->refMag = NAN;
     101    growth->apRef  = NAN;
     102    growth->apLoss = NAN;
     103
    100104    return growth;
    101105}
  • branches/czw_branch/20110406/psModules/src/objects/pmGrowthCurve.h

    r15562 r31606  
    2222    psF32 maxRadius;
    2323    psF32 fitMag;
     24    psF32 refMag;
    2425    psF32 apRef;   // apMag[refRadius]
    2526    psF32 apLoss;  // fitMag - apRef
     27    int refBin;
    2628}
    2729pmGrowthCurve;
  • branches/czw_branch/20110406/psModules/src/objects/pmGrowthCurveGenerate.c

    r29546 r31606  
    5050
    5151#include "pmSourcePhotometry.h"
    52 
    53 pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType markVal, float xc, float yc);
     52#include "pmGrowthCurveGenerate.h"
    5453
    5554/*****************************************************************************/
     
    197196        // mask the given aperture and measure the apMag
    198197        psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
    199         if (!pmSourcePhotometryAper (&apMag, NULL, NULL, model, pixels, NULL, mask, maskVal)) {
     198        if (!pmSourcePhotometryAper (NULL, &apMag, NULL, NULL, model, pixels, NULL, mask, maskVal)) {
    200199            psFree (growth);
    201200            psFree (view);
     
    226225    return growth;
    227226}
     227
     228# define DEBUG 0
     229# if (DEBUG)
     230static FILE *fgr = NULL;
     231# endif
     232
     233// we generate the growth curve for the center of the image with the specified psf model
     234bool pmGrowthCurveGenerateFromSources (pmReadout *readout, pmPSF *psf, psArray *sources, bool INTERPOLATE_AP, psImageMaskType maskVal, psImageMaskType markVal)
     235{
     236    PS_ASSERT_PTR_NON_NULL(readout, false);
     237    PS_ASSERT_PTR_NON_NULL(readout->image, false);
     238
     239    // maskVal is used to test for rejected pixels, and must include markVal
     240    maskVal |= markVal;
     241
     242    pmSourcePhotometryMode photMode = INTERPOLATE_AP ? PM_SOURCE_PHOT_INTERP : 0;
     243   
     244    // measure the growth curve for each PSF source and average them together
     245    psArray *growths = psArrayAllocEmpty (100);
     246
     247# if (DEBUG)
     248    fgr = fopen ("growth.mags.dat", "w");
     249# endif
     250
     251    for (int i = 0; i < sources->n; i++) {
     252
     253        pmSource *source = sources->data[i];
     254
     255        if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
     256
     257        pmGrowthCurve *growth = pmGrowthCurveForSource (source, psf, photMode, maskVal, markVal);
     258        if (!growth) continue;
     259       
     260        psArrayAdd (growths, 100, growth);
     261        psFree (growth);
     262    }
     263    psAssert (growths->n, "cannot build growth curve (no valid PSF stars?)");
     264
     265# if (DEBUG)
     266    fclose (fgr);
     267# endif
     268
     269    // just use a simple sample median to get the 'best' value from each growth curve...
     270    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     271
     272    psVector *values = psVectorAlloc (growths->n, PS_DATA_F32);
     273
     274    // loop over a range of source fluxes
     275    // no need to interpolate since we have forced the object center
     276    // to 0.5, 0.5 above
     277    for (int i = 0; i < psf->growth->radius->n; i++) {
     278
     279        // median the values for each radial bin
     280        values->n = 0;
     281        for (int j = 0; j < growths->n; j++) {
     282            pmGrowthCurve *growth = growths->data[j];
     283            if (!isfinite(growth->apMag->data.F32[i])) continue;
     284            psVectorAppend (values, growth->apMag->data.F32[i] - growth->refMag);
     285        }
     286        if (values->n == 0) {
     287            psf->growth->apMag->data.F32[i] = NAN;
     288        } else {
     289            if (!psVectorStats (stats, values, NULL, NULL, 0)) {
     290                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     291                return false;
     292            }
     293            psf->growth->apMag->data.F32[i] = stats->sampleMedian;
     294        }
     295    }
     296
     297    psf->growth->fitMag = psf->growth->apMag->data.F32[psf->growth->radius->n-1];
     298    psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
     299    psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
     300
     301    psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f (fitMag - apMag @ ref : %f - %f)\n", psf->growth->apLoss, psf->growth->fitMag, psf->growth->apRef);
     302
     303    psFree (growths);
     304    psFree (stats);
     305    psFree (values);
     306
     307    return true;
     308}
     309
     310pmGrowthCurve *pmGrowthCurveForSource (pmSource *source, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal, psImageMaskType markVal) {
     311
     312    float radius;
     313
     314    assert (psf->growth);
     315
     316    float minRadius = psf->growth->radius->data.F32[0];
     317    pmGrowthCurve *growth = pmGrowthCurveAlloc (minRadius, psf->growth->maxRadius, psf->growth->refRadius);
     318
     319    // measure the fitMag for this source (for normalization)
     320    // pmSourcePhotometryModel (&fitMag, NULL, source->psfModel);
     321    growth->fitMag = source->psfMag;
     322
     323    float xc = source->peak->xf;
     324    float yc = source->peak->yf;
     325
     326    // Loop over the range of radii
     327    for (int i = 0; i < growth->radius->n; i++) {
     328
     329        radius = growth->radius->data.F32[i];
     330
     331        // mask the given aperture and measure the apMag
     332        psImageKeepCircle (source->maskObj, xc, yc, radius, "OR", markVal);
     333
     334        if (!pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, radius)) {
     335            psFree (growth);
     336            return NULL;
     337        }
     338
     339        // if (!pmSourcePhotometryAper (NULL, &apMag, NULL, NULL, NULL, source->pixels, NULL, source->maskObj, maskVal)) {
     340        //     psFree (growth);
     341        //     return NULL;
     342        // }
     343
     344        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask
     345
     346        growth->apMag->data.F32[i] = source->apMag;
     347    }
     348    psAssert(growth->refBin >= 0, "invalid growth reference bin");
     349    psAssert(growth->refBin < growth->apMag->n, "invalid growth reference bin");
     350    growth->refMag = growth->apMag->data.F32[growth->refBin];
     351
     352    // Loop over the range of radii
     353# if (DEBUG)
     354    for (int i = 0; i < growth->radius->n; i++) {
     355        fprintf (fgr, "%f %f  %f %f %f %f\n", xc, yc, growth->radius->data.F32[i], growth->apMag->data.F32[i], growth->fitMag, growth->refMag);
     356    }
     357# endif
     358
     359    return growth;
     360}
  • branches/czw_branch/20110406/psModules/src/objects/pmPCMdata.c

    r31153 r31606  
    263263bool pmPCMupdate(pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, pmModel *model) {
    264264
    265     bool newWindow = (source->pixels->numRows != pcm->modelFlux->numRows) || (source->pixels->numCols != pcm->modelFlux->numCols);
     265    bool sameWindow = (source->pixels->numRows == pcm->modelFlux->numRows);
     266    sameWindow     &= (source->pixels->numCols == pcm->modelFlux->numCols);
     267    sameWindow     &= (source->pixels->col0    == pcm->modelFlux->col0);
     268    sameWindow     &= (source->pixels->row0    == pcm->modelFlux->row0);
    266269
    267270    // re-count the number of unmasked pixels:
    268     if (newWindow) {
     271    if (!sameWindow) {
    269272        for (psS32 i = 0; i < source->pixels->numRows; i++) {
    270273            for (psS32 j = 0; j < source->pixels->numCols; j++) {
     
    346349
    347350    // has the source pixel window changed?
    348     if (newWindow) {
     351    if (!sameWindow) {
    349352
    350353        // adjust all supporting images:
  • branches/czw_branch/20110406/psModules/src/objects/pmPSF.c

    r31153 r31606  
    7373
    7474    options->type          = 0;
    75 
    7675    options->stats         = NULL;
    77     options->fitOptions    = NULL; // XXX this has to be set before calling pmPSF fit functions
    7876
    7977    options->psfTrendMode  = PM_TREND_NONE;
     
    9088
    9189    options->chiFluxTrend = true;
    92 
     90    options->fitOptions    = NULL; // XXX this has to be set before calling pmPSF fit functions
     91
     92    options->fitRadius = NAN;
     93    options->apRadius = NAN;
    9394    return options;
    9495}
     
    141142
    142143    psf->type     = options->type;
     144
    143145    psf->chisq    = 0.0;
    144146    psf->ApResid  = 0.0;
  • branches/czw_branch/20110406/psModules/src/objects/pmPSF.h

    r29004 r31606  
    3131struct pmPSF {
    3232    pmModelType type;                   ///< PSF Model in use
    33     psArray *params;                    ///< Model parameters (psPolynomial2D)
    34     psStats *psfTrendStats;             ///< psf parameter trend clipping stats
    35     pmTrend2DMode psfTrendMode;
    36     psPolynomial1D *ChiTrend;           ///< Chisq vs flux fit (correction for systematic errors)
    37     pmTrend2D *ApTrend;                 ///< ApResid vs (x,y)
    38     pmTrend2D *FluxScale;               ///< Flux for PSF at (x,y) for normalization = 1.0
     33
     34    float chisq;                        ///< PSF goodness statistic (unused??)
    3935    float ApResid;                      ///< apMag - psfMag (for PSF stars)
    4036    float dApResid;                     ///< scatter of ApResid
    4137    float skyBias;                      ///< implied residual sky offset from ApResid fit
    4238    float skySat;                       ///< roll-over of ApResid fit
    43     float chisq;                        ///< PSF goodness statistic (unused??)
    4439    int nPSFstars;                      ///< number of stars used to measure PSF
    4540    int nApResid;                       ///< number of stars used to measure ApResid
     41
     42    bool poissonErrorsPhotLMM;          ///< use poission errors for non-linear model fitting
     43    bool poissonErrorsPhotLin;          ///< use poission errors for linear model fitting
     44    bool poissonErrorsParams;           ///< use poission errors for model parameter fitting
     45
     46    pmTrend2D *ApTrend;                 ///< ApResid vs (x,y)
     47    pmTrend2D *FluxScale;               ///< Flux for PSF at (x,y) for normalization = 1.0
     48    psPolynomial1D *ChiTrend;           ///< Chisq vs flux fit (correction for systematic errors)
     49
     50    pmGrowthCurve *growth;              ///< apMag vs Radius
     51    pmResiduals *residuals;             ///< normalized residual image (no spatial variation)
     52
     53    psArray *params;                    ///< Model parameters (psPolynomial2D)
     54    psStats *psfTrendStats;             ///< psf parameter trend clipping stats
     55
     56    pmTrend2DMode psfTrendMode;
    4657    int trendNx;
    4758    int trendNy;
     
    5061    int fieldXo;
    5162    int fieldYo;
    52     bool poissonErrorsPhotLMM;          ///< use poission errors for non-linear model fitting
    53     bool poissonErrorsPhotLin;          ///< use poission errors for linear model fitting
    54     bool poissonErrorsParams;           ///< use poission errors for model parameter fitting
    55     pmGrowthCurve *growth;              ///< apMag vs Radius
    56     pmResiduals *residuals;             ///< normalized residual image (no spatial variation)
    5763};
    5864
     
    6066    pmModelType   type;
    6167    psStats      *stats;                // psfTrend clipping stats
     68
    6269    pmTrend2DMode psfTrendMode;
    6370    int           psfTrendNx;
     
    6774    int           psfFieldXo;
    6875    int           psfFieldYo;
     76
    6977    bool          poissonErrorsPhotLMM; ///< use poission errors for non-linear model fitting
    7078    bool          poissonErrorsPhotLin; ///< use poission errors for linear model fitting
    7179    bool          poissonErrorsParams; ///< use poission errors for model parameter fitting
     80
     81    bool          chiFluxTrend;         // Fit a trend in Chi2 as a function of flux?
     82    pmSourceFitOptions *fitOptions;
     83
    7284    float         fitRadius;
    7385    float         apRadius;
    74     bool          chiFluxTrend;         // Fit a trend in Chi2 as a function of flux?
    75     pmSourceFitOptions *fitOptions;
    7686} pmPSFOptions;
    7787
     
    94104double pmPSF_SXYtoModel (psF32 *fittedPar);
    95105
    96 bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal, psImageMaskType mark);
    97106pmPSF *pmPSFBuildSimple (char *typeName, float sxx, float syy, float sxy, ...);
    98107
  • branches/czw_branch/20110406/psModules/src/objects/pmPSF_IO.c

    r30031 r31606  
    6363
    6464bool pmPSFmodelReadPSFClump (psMetadata *analysis, psMetadata *header);
     65bool pmPSFmodelRead_ApTrend (pmPSF *psf, pmFPAfile *file);
     66bool pmPSFmodelWrite_ApTrend (pmFPAfile *file, pmPSF *psf);
     67
     68bool pmPSFmodelRead_GrowthCurve (pmPSF *psf, pmFPAfile *file);
     69bool pmPSFmodelWrite_GrowthCurve (pmFPAfile *file, pmPSF *psf);
    6570
    6671bool pmPSFmodelCheckDataStatusForView (const pmFPAview *view, const pmFPAfile *file)
     
    197202        psError(psErrorCodeLast(), false, "Failed to write PSF for chip");
    198203        return false;
     204    }
     205    return true;
     206}
     207
     208// XXX we save the model term identifiers (item) as S32, but they probably should be more flexible
     209bool pmTrend2DtoTable (psArray *table, pmTrend2D *trend, char *label, int item) {
     210
     211    if (trend == NULL) return true;
     212
     213    if (trend->mode == PM_TREND_MAP) {
     214        // write the image components into a table: this is needed because they may each be a different size
     215        psImageMap *map = trend->map;
     216        for (int ix = 0; ix < map->map->numCols; ix++) {
     217            for (int iy = 0; iy < map->map->numRows; iy++) {
     218                psMetadata *row = psMetadataAlloc ();
     219                psMetadataAddS32 (row, PS_LIST_TAIL, label,        0, "", item);
     220                psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
     221                psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
     222                psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", map->map->data.F32[iy][ix]);
     223                psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", map->error->data.F32[iy][ix]);
     224                psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", 0); // no cells are masked
     225
     226                psArrayAdd (table, 100, row);
     227                psFree (row);
     228            }
     229        }
     230    } else {
     231        // write the polynomial components into a table
     232        psPolynomial2D *poly = trend->poly;
     233        for (int ix = 0; ix <= poly->nX; ix++) {
     234            for (int iy = 0; iy <= poly->nY; iy++) {
     235                psMetadata *row = psMetadataAlloc ();
     236                psMetadataAddS32 (row, PS_LIST_TAIL, label,        0, "", item);
     237                psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
     238                psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
     239                psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
     240                psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
     241                psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->coeffMask[ix][iy]);
     242
     243                psArrayAdd (table, 100, row);
     244                psFree (row);
     245            }
     246        }
     247    }
     248    return true;
     249}
     250
     251// extra trend2D elements from a row
     252bool pmTrend2DfromTableRow (pmTrend2D *trend, psMetadata *row) {
     253
     254    bool status = false;
     255
     256    int xPow = psMetadataLookupS32 (&status, row, "X_POWER");
     257    int yPow = psMetadataLookupS32 (&status, row, "Y_POWER");
     258
     259    if (trend->mode == PM_TREND_MAP) {
     260        psImageMap *map = trend->map;
     261        assert (map);
     262        assert (map->map);
     263        assert (map->error);
     264        assert (xPow >= 0);
     265        assert (yPow >= 0);
     266        assert (xPow < map->map->numCols);
     267        assert (yPow < map->map->numRows);
     268        map->map->data.F32[yPow][xPow]    = psMetadataLookupF32 (&status, row, "VALUE");
     269        map->error->data.F32[yPow][xPow]  = psMetadataLookupF32 (&status, row, "ERROR");
     270    } else {
     271        psPolynomial2D *poly = trend->poly;
     272        assert (poly);
     273        assert (xPow >= 0);
     274        assert (yPow >= 0);
     275        assert (xPow <= poly->nX);
     276        assert (yPow <= poly->nY);
     277        poly->coeff[xPow][yPow]     = psMetadataLookupF32 (&status, row, "VALUE");
     278        poly->coeffErr[xPow][yPow]  = psMetadataLookupF32 (&status, row, "ERROR");
     279        poly->coeffMask[xPow][yPow] = psMetadataLookupU8  (&status, row, "MASK");
    199280    }
    200281    return true;
     
    403484
    404485            if (trend->mode == PM_TREND_MAP) {
    405               nX = trend->map->map->numCols;
    406               nY = trend->map->map->numRows;
     486                nX = trend->map->map->numCols;
     487                nY = trend->map->map->numRows;
    407488            } else {
    408               nX = trend->poly->nX;
    409               nY = trend->poly->nY;
     489                nX = trend->poly->nX;
     490                nY = trend->poly->nY;
    410491            }
    411492            snprintf (name, 9, "PAR%02d_NX", i);
     
    428509        psMetadataAddF32 (header, PS_LIST_TAIL, "SKY_BIAS", PS_DATA_F32, "sky bias level", psf->skyBias);
    429510
     511        float PSF_APERTURE =  psMetadataLookupF32(&status, roAnalysis, "PSF_APERTURE");
     512        if (status) {
     513            psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_APERTURE", PS_DATA_F32, "aperture for psf objects", PSF_APERTURE);
     514        }
     515        float PSF_FIT_RADIUS =  psMetadataLookupF32(&status, roAnalysis, "PSF_FIT_RADIUS");
     516        if (status) {
     517            psMetadataAddF32 (header, PS_LIST_TAIL, "PSF_FIT_RADIUS", PS_DATA_F32, "aperture for psf objects", PSF_FIT_RADIUS);
     518        }
     519
    430520        // build a FITS table of the PSF parameters
    431521        psArray *psfTable = psArrayAllocEmpty (100);
    432522        for (int i = 0; i < nPar; i++) {
    433523            pmTrend2D *trend = psf->params->data[i];
    434             if (trend == NULL) continue; // skip unset parameters (eg, XPOS)
    435 
    436             if (trend->mode == PM_TREND_MAP) {
    437                 // write the image components into a table: this is needed because they may each be a different size
    438                 psImageMap *map = trend->map;
    439                 for (int ix = 0; ix < map->map->numCols; ix++) {
    440                     for (int iy = 0; iy < map->map->numRows; iy++) {
    441                         psMetadata *row = psMetadataAlloc ();
    442                         psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TERM", 0, "", i);
    443                         psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
    444                         psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
    445                         psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", map->map->data.F32[iy][ix]);
    446                         psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", map->error->data.F32[iy][ix]);
    447                         psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", 0); // no cells are masked
    448 
    449                         psArrayAdd (psfTable, 100, row);
    450                         psFree (row);
    451                     }
    452                 }
    453             } else {
    454                 // write the polynomial components into a table
    455                 psPolynomial2D *poly = trend->poly;
    456                 for (int ix = 0; ix <= poly->nX; ix++) {
    457                     for (int iy = 0; iy <= poly->nY; iy++) {
    458                         psMetadata *row = psMetadataAlloc ();
    459                         psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TERM", 0, "", i);
    460                         psMetadataAddS32 (row, PS_LIST_TAIL, "X_POWER",    0, "", ix);
    461                         psMetadataAddS32 (row, PS_LIST_TAIL, "Y_POWER",    0, "", iy);
    462                         psMetadataAddF32 (row, PS_LIST_TAIL, "VALUE",      0, "", poly->coeff[ix][iy]);
    463                         psMetadataAddF32 (row, PS_LIST_TAIL, "ERROR",      0, "", poly->coeffErr[ix][iy]);
    464                         psMetadataAddU8  (row, PS_LIST_TAIL, "MASK",       0, "", poly->coeffMask[ix][iy]);
    465 
    466                         psArrayAdd (psfTable, 100, row);
    467                         psFree (row);
    468                     }
    469                 }
    470             }
     524            pmTrend2DtoTable (psfTable, trend, "MODEL_TERM", i);
    471525        }
    472526
     
    547601    }
    548602
     603    if (!pmPSFmodelWrite_ApTrend(file, psf)) {
     604        psError(psErrorCodeLast(), false, "Unable to write PSF ApTrend");
     605        return false;
     606    }
     607
     608    if (!pmPSFmodelWrite_GrowthCurve(file, psf)) {
     609        psError(psErrorCodeLast(), false, "Unable to write PSF Growth Curve");
     610        return false;
     611    }
     612
    549613    // write a representation of the psf model
    550614    {
    551615        psMetadata *header = psMetadataAlloc ();
    552 
    553         if (0) {
    554             // set some header keywords to make it clear there are no residuals?
    555             if (!psFitsWriteBlank (file->fits, header, residName)) {
    556                 psError(psErrorCodeLast(), false, "Unable to write blank PSF residuals.");
    557                 psFree(residName);
    558                 psFree(header);
    559                 return false;
    560             }
    561             psFree (residName);
    562             psFree (header);
    563             return true;
    564         }
    565616
    566617        int DX = 65;
     
    651702}
    652703
     704
     705
    653706// if this file needs to have a PHU written out, write one
    654707bool pmPSFmodelWritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config)
     
    934987    psf->skyBias   = psMetadataLookupF32 (&status, header, "SKY_BIAS");
    935988
     989    if (roAnalysis) {
     990        float PSF_APERTURE =  psMetadataLookupF32(&status, header, "PSF_APERTURE");
     991        if (status) {
     992            psMetadataAddF32 (roAnalysis, PS_LIST_TAIL, "PSF_APERTURE", PS_DATA_F32, "aperture for psf objects", PSF_APERTURE);
     993        }
     994        float PSF_FIT_RADIUS =  psMetadataLookupF32(&status, header, "PSF_FIT_RADIUS");
     995        if (status) {
     996            psMetadataAddF32 (roAnalysis, PS_LIST_TAIL, "PSF_FIT_RADIUS", PS_DATA_F32, "aperture for psf objects", PSF_FIT_RADIUS);
     997        }
     998    } else {
     999        psWarning ("unable to read PSF_APERTURE or PSF_FIT_RADIUS");
     1000    }
     1001
    9361002    // read the raw table data
    9371003    psArray *table = psFitsReadTable (file->fits);
     
    9451011    for (int i = 0; i < table->n; i++) {
    9461012        psMetadata *row = table->data[i];
     1013
    9471014        int iPar = psMetadataLookupS32 (&status, row, "MODEL_TERM");
    948         int xPow = psMetadataLookupS32 (&status, row, "X_POWER");
    949         int yPow = psMetadataLookupS32 (&status, row, "Y_POWER");
    9501015
    9511016        pmTrend2D *trend = psf->params->data[iPar];
     
    9551020        }
    9561021
    957         if (trend->mode == PM_TREND_MAP) {
    958             psImageMap *map = trend->map;
    959             assert (map);
    960             assert (map->map);
    961             assert (map->error);
    962             assert (xPow >= 0);
    963             assert (yPow >= 0);
    964             assert (xPow < map->map->numCols);
    965             assert (yPow < map->map->numRows);
    966             map->map->data.F32[yPow][xPow]    = psMetadataLookupF32 (&status, row, "VALUE");
    967             map->error->data.F32[yPow][xPow]  = psMetadataLookupF32 (&status, row, "ERROR");
    968         } else {
    969             psPolynomial2D *poly = trend->poly;
    970             assert (poly);
    971             assert (xPow >= 0);
    972             assert (yPow >= 0);
    973             assert (xPow <= poly->nX);
    974             assert (yPow <= poly->nY);
    975             poly->coeff[xPow][yPow]     = psMetadataLookupF32 (&status, row, "VALUE");
    976             poly->coeffErr[xPow][yPow]  = psMetadataLookupF32 (&status, row, "ERROR");
    977             poly->coeffMask[xPow][yPow] = psMetadataLookupU8  (&status, row, "MASK");
    978         }
     1022        pmTrend2DfromTableRow(trend, row);
    9791023    }
    9801024    psFree (header);
     
    10631107    }
    10641108
     1109    if (!pmPSFmodelRead_ApTrend (psf, file)) {
     1110        psError(psErrorCodeLast(), false, "Unable to read PSF ApTrend data.");
     1111        return false;
     1112    }
     1113
     1114    if (!pmPSFmodelRead_GrowthCurve(psf, file)) {
     1115        psError(psErrorCodeLast(), false, "Unable to read PSF Growth Curve");
     1116        return false;
     1117    }
     1118
    10651119    psMetadataAdd (chipAnalysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
    10661120    psFree (psf);
     
    10701124    psFree (header);
    10711125
     1126    return true;
     1127}
     1128
     1129// write aperture trend to a FITS table
     1130bool pmPSFmodelWrite_ApTrend (pmFPAfile *file, pmPSF *psf) {
     1131
     1132    pmTrend2D *trend = psf->ApTrend;
     1133    if (trend == NULL) {
     1134        psWarning ("no PSF ApTrend to write out, skipping");
     1135        return true;
     1136    }
     1137
     1138    // we need to write a header for the table,
     1139    psMetadata *header = psMetadataAlloc();
     1140
     1141    int nX = 0, nY = 0;
     1142    if (trend->mode == PM_TREND_MAP) {
     1143        nX = trend->map->map->numCols;
     1144        nY = trend->map->map->numRows;
     1145    } else {
     1146        nX = trend->poly->nX;
     1147        nY = trend->poly->nY;
     1148    }
     1149    psMetadataAddS32 (header, PS_LIST_TAIL, "TREND_NX", 0, "", nX);
     1150    psMetadataAddS32 (header, PS_LIST_TAIL, "TREND_NY", 0, "", nY);
     1151    char *modeName = pmTrend2DModeToString (trend->mode);
     1152    psMetadataAddStr (header, PS_LIST_TAIL, "TREND_MD", 0, "", modeName);
     1153    psFree (modeName);
     1154
     1155    // build a FITS table of the ApTrend (only 1)
     1156    psArray *table = psArrayAllocEmpty (100);
     1157    pmTrend2DtoTable (table, trend, "APTREND", 0);
     1158
     1159    // write an empty FITS segment if we have no PSF information
     1160    if (table->n == 0) {
     1161        psError(PM_ERR_PROG, true, "No PSF data to write.");
     1162        psFree(table);
     1163        psFree(header);
     1164        return false;
     1165    }
     1166
     1167    psTrace ("pmFPAfile", 5, "writing psf ApTrend data %s\n", "AP_TREND");
     1168    if (!psFitsWriteTable(file->fits, header, table, "AP_TREND")) {
     1169        psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", "AP_TREND");
     1170        psFree(table);
     1171        psFree(header);
     1172        return false;
     1173    }
     1174
     1175    psFree (table);
     1176    psFree (header);
     1177    return true;
     1178}
     1179
     1180// read aperture trend to a FITS table
     1181bool pmPSFmodelRead_ApTrend (pmPSF *psf, pmFPAfile *file) {
     1182
     1183    bool status;
     1184
     1185    // move fits pointer to AP_TREND section
     1186    // advance to the table data extension
     1187    if (!psFitsMoveExtNameClean (file->fits, "AP_TREND")) {
     1188        psWarning ("no Aperture Trend data in PSF file, skipping");
     1189        return true;
     1190    }
     1191
     1192    psMetadata *header = psFitsReadHeader (NULL, file->fits);
     1193    if (!header) {
     1194        psError(psErrorCodeLast(), false, "Unable to read AP_TREND header.");
     1195        return false;
     1196    }
     1197       
     1198    // read the raw table data
     1199    psArray *table = psFitsReadTable (file->fits);
     1200    if (!table) {
     1201        psError(psErrorCodeLast(), false, "Unable to read AP_TREND table.");
     1202        psFree(header);
     1203        return false;
     1204    }
     1205
     1206    // XXX allow user to set this optionally?
     1207    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     1208
     1209    psImageBinning *binning = psImageBinningAlloc();
     1210    binning->nXfine = psf->fieldNx;
     1211    binning->nYfine = psf->fieldNy;
     1212    binning->nXruff = psMetadataLookupS32 (&status, header, "TREND_NX");
     1213    binning->nYruff = psMetadataLookupS32 (&status, header, "TREND_NY");
     1214    psImageBinningSetScale (binning, PS_IMAGE_BINNING_CENTER);
     1215    char *modeName  = psMetadataLookupStr (&status, header, "TREND_MD");
     1216    if (!status) {
     1217        psError(PM_ERR_PROG, true, "inconsistent PSF header: NX & NY defined for AP TREND, but not MD");
     1218        psFree (header);
     1219        psFree (stats);
     1220        psFree (table);
     1221        return false;
     1222    }
     1223    pmTrend2DMode psfTrendMode = pmTrend2DModeFromString (modeName);
     1224    if (psfTrendMode == PM_TREND_NONE) {
     1225        psfTrendMode = PM_TREND_POLY_ORD;
     1226    }
     1227
     1228    // measure Trend2D for the current spatial scale
     1229    pmTrend2D *apTrend = pmTrend2DNoImageAlloc (PM_TREND_MAP, binning, stats);
     1230
     1231    // fill in the matching psf->params entries
     1232    for (int i = 0; i < table->n; i++) {
     1233        psMetadata *row = table->data[i];
     1234        pmTrend2DfromTableRow(apTrend, row);
     1235    }
     1236    psf->ApTrend = apTrend;
     1237
     1238    psFree (binning);
     1239    psFree (header);
     1240    psFree (stats);
     1241    psFree (table);
     1242    return true;
     1243}
     1244
     1245// write aperture trend to a FITS table
     1246bool pmPSFmodelWrite_GrowthCurve (pmFPAfile *file, pmPSF *psf) {
     1247
     1248    pmGrowthCurve *growth = psf->growth;
     1249    if (growth == NULL) {
     1250        psWarning ("no PSF Growth Curve to write out, skipping");
     1251        return true;
     1252    }
     1253
     1254    // we need to write a header for the table,
     1255    psMetadata *header = psMetadataAlloc();
     1256
     1257    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_MIN_RAD", 0, "", growth->radius->data.F32[0]);
     1258    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_MAX_RAD", 0, "", growth->maxRadius);
     1259    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_REF_RAD", 0, "", growth->refRadius);
     1260    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_AP_LOSS", 0, "", growth->apLoss);
     1261    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_AP_REF",  0, "", growth->apRef);
     1262    psMetadataAddF32 (header, PS_LIST_TAIL, "GROWTH_FIT_MAG", 0, "", growth->fitMag);
     1263
     1264    // build a FITS table of the ApTrend (only 1)
     1265    psArray *table = psArrayAllocEmpty (100);
     1266    for (int i = 0; i < growth->apMag->n; i++) {
     1267        psMetadata *row = psMetadataAlloc ();
     1268        psMetadataAddF32 (row, PS_LIST_TAIL, "RADIUS", 0, "", growth->radius->data.F32[i]);
     1269        psMetadataAddF32 (row, PS_LIST_TAIL, "AP_MAG", 0, "", growth->apMag->data.F32[i]);
     1270        psArrayAdd (table, 100, row);
     1271        psFree (row);
     1272    }
     1273
     1274    // write an empty FITS segment if we have no PSF information
     1275    if (table->n == 0) {
     1276        psError(PM_ERR_PROG, true, "No PSF data to write.");
     1277        psFree(table);
     1278        psFree(header);
     1279        return false;
     1280    }
     1281
     1282    psTrace ("pmFPAfile", 5, "writing psf Growth Curve data %s\n", "GROWTH_CURVE");
     1283    if (!psFitsWriteTable(file->fits, header, table, "GROWTH_CURVE")) {
     1284        psError(psErrorCodeLast(), false, "Error writing psf table data %s\n", "GROWTH_CURVE");
     1285        psFree(table);
     1286        psFree(header);
     1287        return false;
     1288    }
     1289
     1290    psFree (table);
     1291    psFree (header);
     1292    return true;
     1293}
     1294
     1295// read aperture trend to a FITS table
     1296bool pmPSFmodelRead_GrowthCurve (pmPSF *psf, pmFPAfile *file) {
     1297
     1298    bool status;
     1299
     1300    // move fits pointer to AP_TREND section
     1301    // advance to the table data extension
     1302    if (!psFitsMoveExtNameClean (file->fits, "GROWTH_CURVE")) {
     1303        psWarning ("no Growth Curve data in PSF file, skipping");
     1304        return true;
     1305    }
     1306
     1307    psMetadata *header = psFitsReadHeader (NULL, file->fits);
     1308    if (!header) {
     1309        psError(psErrorCodeLast(), false, "Unable to read GROWTH_CURVE header.");
     1310        return false;
     1311    }
     1312       
     1313    // read the raw table data
     1314    psArray *table = psFitsReadTable (file->fits);
     1315    if (!table) {
     1316        psError(psErrorCodeLast(), false, "Unable to read GROWTH_CURVE table.");
     1317        psFree(header);
     1318        return false;
     1319    }
     1320
     1321    float minRadius = psMetadataLookupF32 (&status, header, "GROWTH_MIN_RAD"); if (!status) return false;
     1322    float maxRadius = psMetadataLookupF32 (&status, header, "GROWTH_MAX_RAD"); if (!status) return false;
     1323    float refRadius = psMetadataLookupF32 (&status, header, "GROWTH_REF_RAD"); if (!status) return false;
     1324
     1325    psf->growth = pmGrowthCurveAlloc(minRadius, maxRadius, refRadius);
     1326
     1327    psf->growth->apLoss = psMetadataLookupF32 (&status, header, "GROWTH_AP_LOSS"); if (!status) return false;
     1328    psf->growth->apRef  = psMetadataLookupF32 (&status, header, "GROWTH_AP_REF"); if (!status) return false;
     1329    psf->growth->fitMag = psMetadataLookupF32 (&status, header, "GROWTH_FIT_MAG"); if (!status) return false;
     1330
     1331    // fill in the matching psf->params entries
     1332    for (int i = 0; i < table->n; i++) {
     1333        psMetadata *row = table->data[i];
     1334        psf->growth->apMag->data.F32[i] = psMetadataLookupF32 (&status, row, "AP_MAG"); if (!status) return false;
     1335    }
     1336
     1337    psFree (header);
     1338    psFree (table);
    10721339    return true;
    10731340}
  • branches/czw_branch/20110406/psModules/src/objects/pmPSFtryFitPSF.c

    r31153 r31606  
    122122        psfTry->fitMag->data.F32[i] = source->psfMag;
    123123        psfTry->metric->data.F32[i] = source->apMag - source->psfMag;
    124         psfTry->metricErr->data.F32[i] = source->errMag;
     124        psfTry->metricErr->data.F32[i] = source->psfMagErr;
    125125
    126126        // XXX this did not work: modifies shape of psf too much
     
    131131                 source->peak->xf, source->peak->yf,
    132132                 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS],
    133                  source->psfMag, source->apMag, source->errMag,
     133                 source->psfMag, source->apMag, source->psfMagErr,
    134134                 source->modelPSF->params->data.F32[PM_PAR_I0],
    135135                 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY],
  • branches/czw_branch/20110406/psModules/src/objects/pmPeaks.c

    r31153 r31606  
    150150    tmp->x = x;
    151151    tmp->y = y;
     152    tmp->xf = x;
     153    tmp->yf = y;
     154    tmp->dx = NAN;
     155    tmp->dy = NAN;
    152156    tmp->detValue        = value;
    153157    tmp->rawFlux         = value; // set this by default: it is up to the user to supply a better value
     
    155159    tmp->smoothFlux      = value; // set this by default: it is up to the user to supply a better value
    156160    tmp->smoothFluxStdev = NAN;
    157     // tmp->SN = 0;
    158     tmp->xf = x;
    159     tmp->yf = y;
    160161    tmp->assigned = false;
    161162    tmp->type = type;
     
    166167    psTrace("psModules.objects", 10, "---- %s() end ----\n", __func__);
    167168    return(tmp);
     169}
     170
     171// copy to an already allocated peak
     172bool pmPeakCopy(pmPeak *out, pmPeak *in)
     173{
     174    out->x               = in->x;
     175    out->y               = in->y;
     176    out->xf              = in->xf;
     177    out->yf              = in->yf;
     178    out->dx              = in->dx;
     179    out->dy              = in->dy;
     180    out->detValue        = in->detValue;
     181    out->rawFlux         = in->rawFlux;
     182    out->rawFluxStdev    = in->rawFluxStdev;
     183    out->smoothFlux      = in->smoothFlux;
     184    out->smoothFluxStdev = in->smoothFluxStdev;
     185    out->assigned        = in->assigned;
     186    out->type            = in->type;
     187
     188    return true;
    168189}
    169190
  • branches/czw_branch/20110406/psModules/src/objects/pmPeaks.h

    r31153 r31606  
    6969    float smoothFlux;                   ///< peak flux in smoothed signal image
    7070    float smoothFluxStdev;              ///< peak stdev in smoothed signal image
    71     // float SNestimated;                  ///< S/N estimated from the detection image
    7271    bool assigned;                      ///< is peak assigned to a source?
    7372    pmPeakType type;                    ///< Description of peak.
     
    8988
    9089bool psMemCheckPeak(psPtr ptr);
     90
     91bool pmPeakCopy(pmPeak *out, pmPeak *in);
    9192
    9293/** pmPeaksInVector()
  • branches/czw_branch/20110406/psModules/src/objects/pmSource.c

    r31153 r31606  
    116116    source->psfImage = NULL;
    117117    source->moments = NULL;
    118     source->blends = NULL;
    119118    source->modelPSF = NULL;
    120119    source->modelEXT = NULL;
     
    124123    source->mode2 = PM_SOURCE_MODE_DEFAULT;
    125124    source->tmpFlags = 0;
    126     source->extpars = NULL;
    127     source->diffStats = NULL;
    128     source->radialAper = NULL;
    129     source->parent = NULL;
    130 
    131     source->region = psRegionSet(NAN, NAN, NAN, NAN);
    132     psMemSetDeallocator(source, (psFreeFunc) sourceFree);
    133125
    134126    // default values are NAN
    135127    source->psfMag           = NAN;
     128    source->psfMagErr        = NAN;
    136129    source->psfFlux          = NAN;
    137130    source->psfFluxErr       = NAN;
    138131    source->extMag           = NAN;   
    139     source->errMag           = NAN;
    140132    source->apMag            = NAN;
    141133    source->apMagRaw         = NAN;
     
    143135    source->apFlux           = NAN;
    144136    source->apFluxErr        = NAN;
    145     source->sky              = NAN;
    146     source->skyErr           = NAN;   
     137
    147138    source->pixWeightNotBad  = NAN;
    148139    source->pixWeightNotPoor = NAN;
     
    151142    source->crNsigma         = NAN;
    152143    source->extNsigma        = NAN;
     144    source->sky              = NAN;
     145    source->skyErr           = NAN;   
     146
     147    source->region = psRegionSet(NAN, NAN, NAN, NAN);
     148    source->blends = NULL;
     149    source->extpars = NULL;
     150    source->diffStats = NULL;
     151    source->radialAper = NULL;
     152    source->parent = NULL;
     153    source->imageID = -1;
     154
     155    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
    153156
    154157    psTrace("psModules.objects", 10, "---- end ----\n");
     
    172175    if (in->peak != NULL) {
    173176        source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->detValue, in->peak->type);
    174         source->peak->xf = in->peak->xf;
    175         source->peak->yf = in->peak->yf;
    176         source->peak->rawFlux         = in->peak->rawFlux;
    177         source->peak->rawFluxStdev    = in->peak->rawFluxStdev;
    178         source->peak->smoothFlux      = in->peak->smoothFlux;
    179         source->peak->smoothFluxStdev = in->peak->smoothFluxStdev;
    180         // source->peak->SN = in->peak->SN;
     177        pmPeakCopy(source->peak, in->peak);
    181178    }
    182179
     
    195192
    196193    // the maskObj is a unique mask array; create a new mask image
    197     source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL;
    198 
    199     source->type = in->type;
    200     source->mode = in->mode;
    201     source->imageID = in->imageID;
     194    source->maskObj = in->maskObj   ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL;
     195
     196    // NOTE : because of the const id element, we cannot just assign *source = *in
     197
     198    source->type             = in->type;
     199    source->mode             = in->mode;
     200    source->mode2            = in->mode2;
     201    source->tmpFlags         = in->tmpFlags;
     202    source->psfMag           = in->psfMag;
     203    source->psfMagErr        = in->psfMagErr;
     204    source->psfFlux          = in->psfFlux;
     205    source->psfFluxErr       = in->psfFluxErr;
     206    source->extMag           = in->extMag;
     207    source->apMag            = in->apMag;
     208    source->apMagRaw         = in->apMagRaw;
     209    source->apRadius         = in->apRadius;
     210    source->apFlux           = in->apFlux;
     211    source->apFluxErr        = in->apFluxErr;
     212    source->pixWeightNotBad  = in->pixWeightNotBad;
     213    source->pixWeightNotPoor = in->pixWeightNotPoor;
     214    source->psfChisq         = in->psfChisq;
     215    source->crNsigma         = in->crNsigma;
     216    source->extNsigma        = in->extNsigma;
     217    source->sky              = in->sky;
     218    source->skyErr           = in->skyErr;
     219
     220    source->region           = in->region;
    202221
    203222    return(source);
     
    266285    extend |= (mySource->maskObj == NULL);
    267286    extend |= (mySource->maskView == NULL);
     287
     288    // if ((fabs(x - 2020) < 5) && (fabs(y - 366) < 5)) {
     289    //  if (extend) {
     290    //      fprintf (stderr, "extend T, %f, %f : %f, %f vs %f, %f : %f, %f\n",
     291    //               newRegion.x0, newRegion.y0, newRegion.x1, newRegion.y1,
     292    //               mySource->region.x0, mySource->region.y0, mySource->region.x1, mySource->region.y1);
     293    //  } else {
     294    //      fprintf (stderr, "extend F, %f, %f : %f, %f vs %f, %f : %f, %f\n",
     295    //               newRegion.x0, newRegion.y0, newRegion.x1, newRegion.y1,
     296    //               mySource->region.x0, mySource->region.y0, mySource->region.x1, mySource->region.y1);
     297    //  }
     298    // }
    268299
    269300    if (extend) {
     
    486517        // create vectors with Sx, Sy values in window
    487518        // clip sources based on S/N
    488         for (psS32 i = 0 ; i < sources->n ; i++)
     519        for (psS32 i = 0; i < sources->n; i++)
    489520        {
    490521            pmSource *tmpSrc = (pmSource *) sources->data[i];
     
    11751206    if (!source->moments) return false;          // can't if there are no moments
    11761207    if (!source->moments->nPixels) return false; // can't if the moments were not measured
    1177     if (source->mode && PM_SOURCE_MODE_MOMENTS_FAILURE) return false; // can't if the moments failed...
     1208    if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) return false; // can't if the moments failed...
    11781209
    11791210    if (source->mode & PM_SOURCE_MODE_SATSTAR) return true; // moments are best for SATSTARs
  • branches/czw_branch/20110406/psModules/src/objects/pmSource.h

    r31153 r31606  
    8080    pmSourceMode2 mode2;                ///< analysis flags set for object.
    8181    pmSourceTmpF tmpFlags;              ///< internal-only flags
    82     psArray *blends;                    ///< collection of sources thought to be confused with object
     82
    8383    float psfMag;                       ///< calculated from flux in modelPSF
     84    float psfMagErr;                    ///< error in psfMag
    8485    float psfFlux;                      ///< calculated from flux in modelPSF
    85     float psfFluxErr;                   ///< calculated from flux in modelPSF
    86     float extMag;                       ///< calculated from flux in modelEXT
    87     float errMag;                       ///< error in psfMag OR extMag (depending on type)
     86    float psfFluxErr;                   ///< error in psfFlux
     87    float extMag;                       ///< calculated from flux in modelEXT -- NOTE this is not actually used
    8888    float apMag;                        ///< apMag corresponding to psfMag or extMag (depending on type)
    8989    float apMagRaw;                     ///< raw mag in given aperture
     
    9898    float crNsigma;                     ///< Nsigma deviation from PSF to CR
    9999    float extNsigma;                    ///< Nsigma deviation from PSF to EXT
    100     float sky, skyErr;                  ///< The sky and its error at the center of the object
     100    float sky;                          ///< The sky at the center of the object
     101    float skyErr;                       ///< The sky error at the center of the object
     102
    101103    psRegion region;                    ///< area on image covered by selected pixels
     104    psArray *blends;                    ///< collection of sources thought to be confused with object
    102105    pmSourceExtendedPars *extpars;      ///< extended source parameters
    103106    pmSourceDiffStats *diffStats;       ///< extra parameters for difference detections
     
    254257    float sigma,      ///< size of Gaussian window function (<= 0.0 -> skip window)
    255258    float minSN,              ///< minimum pixel significance
     259    float minKronRadius,      ///< minimum pixel significance
    256260    psImageMaskType maskVal
    257261);
     
    273277  float xGuess, float yGuess);
    274278
     279float pmSourceMinKronRadius(psArray *sources, float PSF_SN_LIM);
     280
    275281pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source);
    276282
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_DV1.c

    r31153 r31606  
    125125        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    126126        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    127         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     127        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    128128        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfFlux);
    129129        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfFluxErr);
     
    256256
    257257        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    258         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     258        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    259259        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    260260
    261261        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    262262        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    263         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     263        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    264264
    265265        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_DV2.c

    r31153 r31606  
    124124        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    125125        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    126         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     126        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    127127        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfFlux);
    128128        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfFluxErr);
     
    274274
    275275        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    276         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     276        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    277277        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    278278
    279279        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    280280        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    281         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     281        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    282282
    283283        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c

    r31153 r31606  
    125125        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    126126        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    127         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     127        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    128128        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental flux (counts)",         source->psfFlux);
    129129        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental flux",             source->psfFluxErr);
     
    273273        // XXX use these to determine PAR[PM_PAR_I0]?
    274274        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    275         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     275        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    276276        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    277277
    278278        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    279279        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    280         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     280        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    281281
    282282        pmPSF_AxesToModel (PAR, axes);
     
    720720      sprintf (keyword1, "RMIN_%02d", i);
    721721      sprintf (keyword2, "RMAX_%02d", i);
    722       psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]);
    723       psMetadataAddF32 (imageHeader, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]);
     722      psMetadataAddF32 (outhead, PS_LIST_TAIL, keyword1, PS_META_REPLACE, "min radius for SB profile", radMin->data.F32[i]);
     723      psMetadataAddF32 (outhead, PS_LIST_TAIL, keyword2, PS_META_REPLACE, "min radius for SB profile", radMax->data.F32[i]);
    724724    }
    725725
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_V1.c

    r31153 r31606  
    118118        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    119119        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    120         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     120        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    121121        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    122122        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              outputs.apRadius);
     
    241241        // XXX use these to determine PAR[PM_PAR_I0]?
    242242        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    243         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     243        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    244244        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    245245
    246246        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    247247        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    248         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     248        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    249249
    250250        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_V2.c

    r31153 r31606  
    116116        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    117117        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    118         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     118        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    119119        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG",           PS_DATA_F32, "magnitude in standard aperture",             source->apMag);
    120120        psMetadataAdd (row, PS_LIST_TAIL, "AP_MAG_RADIUS",    PS_DATA_F32, "radius used for aperture mags",              outputs.apRadius);
     
    247247        // XXX use these to determine PAR[PM_PAR_I0]?
    248248        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    249         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     249        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    250250        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    251251
    252252        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    253253        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    254         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     254        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    255255
    256256        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMF_PS1_V3.c

    r31153 r31606  
    116116        psMetadataAdd (row, PS_LIST_TAIL, "PLTSCALE",         PS_DATA_F32, "plate scale at source (arcsec/pixel)",       outputs.pltScale);
    117117        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    118         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->errMag);
     118        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        source->psfMagErr);
    119119        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX",    PS_DATA_F32, "PSF fit instrumental flux (counts)",         source->psfFlux);
    120120        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_FLUX_SIG",PS_DATA_F32, "Sigma of PSF instrumental flux",             source->psfFluxErr);
     
    161161        psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_INNER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kinner);
    162162        psMetadataAdd (row, PS_LIST_TAIL, "KRON_FLUX_OUTER",  PS_DATA_F32, "Kron Flux (in 2.5 R1)",                      moments.Kouter);
     163
     164        // Do NOT write these : not consistent with the definition of PS1_V3 in Ohana/src/libautocode/dev/cmf-ps1-v3.d
    163165        // psMetadataAdd (row, PS_LIST_TAIL, "KRON_CORE_FLUX",   PS_DATA_F32, "Kron Flux (in 1.0 R1)",                      moments.KronCore);
    164         // psMetadataAdd (row, PS_LIST_TAIL, "KRON_CORE_ERROR",  PS_DATA_F32, "Kron Error (in 1.0 R1)",                     moments.KronCoreErr);
     166        // psMetadataAdd (row, PS_LIST_TAIL, "KRON_CORE_ERROR",  PS_DATA_F32, "Kron Error (in 1.0 R1)",                     moments.KronCoreErr);
    165167        psMetadataAdd (row, PS_LIST_TAIL, "FLAGS",            PS_DATA_U32, "psphot analysis flags",                      source->mode);
    166168        psMetadataAdd (row, PS_LIST_TAIL, "FLAGS2",           PS_DATA_U32, "psphot analysis flags",                      source->mode2);
     
    270272        // XXX use these to determine PAR[PM_PAR_I0]?
    271273        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    272         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     274        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    273275        source->apMag     = psMetadataLookupF32 (&status, row, "AP_MAG");
    274276
    275277        // XXX this scaling is incorrect: does not include the 2 \pi AREA factor
    276278        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    277         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     279        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    278280
    279281        pmPSF_AxesToModel (PAR, axes);
     
    292294
    293295        // we no longer sort by S/N, only flux
    294         // if (isfinite (source->errMag) && (source->errMag > 0.0)) {
    295         //   source->peak->SN = 1.0 / source->errMag;
     296        // if (isfinite (source->psfMagErr) && (source->psfMagErr > 0.0)) {
     297        //   source->peak->SN = 1.0 / source->psfMagErr;
    296298        // } else {
    297299        //   source->peak->SN = sqrt(source->peak->flux); // an alternate proxy: various functions sort by peak S/N
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_CMP.c

    r29004 r31606  
    137137        axes = pmPSF_ModelToAxes (PAR, 20.0);
    138138
    139         float errMag = isfinite(source->errMag) ? source->errMag : 999;
     139        float psfMagErr = isfinite(source->psfMagErr) ? source->psfMagErr : 999;
    140140
    141141        psLineInit (line);
     
    143143        psLineAdd (line, "%6.1f ",  PAR[PM_PAR_YPOS]);
    144144        psLineAdd (line, "%6.3f ",  PS_MIN (99.0, source->psfMag + ZERO_POINT));
    145         psLineAdd (line, "%03d ",   PS_MIN (999, (int)errMag));
     145        psLineAdd (line, "%03d ",   PS_MIN (999, (int)psfMagErr));
    146146        psLineAdd (line, "%2d ",    type);
    147147        psLineAdd (line, "%3.1f ",  lsky);
     
    280280            source->psfMag = atof (array->data[2]);
    281281            source->extMag = atof (array->data[6]);
    282             source->errMag = atof (array->data[3]) / 1000.0;
     282            source->psfMagErr = atof (array->data[3]) / 1000.0;
    283283            source->apMag  = atof (array->data[7]);
    284284            axes.major     = atof (array->data[8]);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_PS1_CAL_0.c

    r31153 r31606  
    7171    psF32 xPos, yPos;
    7272    psF32 xErr, yErr;
    73     psF32 errMag, chisq;
     73    psF32 psfMagErr, chisq;
    7474
    7575    pmChip *chip = readout->parent->parent;
     
    121121            chisq = model->chisq;
    122122
    123             // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
    124             errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
     123            // need to determine the PSF photometry error: source->psfMagErr is the error on the 'best' model mag.
     124            psfMagErr = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
    125125        } else {
    126126            xPos = source->peak->xf;
     
    132132            axes.theta = NAN;
    133133            chisq = NAN;
    134             errMag = NAN;
     134            psfMagErr = NAN;
    135135        }
    136136
     
    167167        psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr);
    168168        psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG",      PS_DATA_F32, "Calibrated Magnitude from PSF Fit",          calMag);
    169         psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "Calibrated Magnitude Error",                 errMag);
     169        psMetadataAdd (row, PS_LIST_TAIL, "CAL_PSF_MAG_SIG",  PS_DATA_F32, "Calibrated Magnitude Error",                 psfMagErr);
    170170        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    171         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        errMag);
     171        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        psfMagErr);
    172172        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           peakMag);
    173173        psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
     
    284284        // XXX use these to determine PAR[PM_PAR_I0]?
    285285        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    286         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     286        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    287287        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    288         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     288        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    289289
    290290        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_PS1_DEV_0.c

    r31153 r31606  
    113113        psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr);
    114114        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             PS_MIN (99.0, source->psfMag));
    115         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        PS_MIN (99.0, source->errMag));
     115        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        PS_MIN (99.0, source->psfMagErr));
    116116        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           PS_MIN (99.0, peakMag));
    117117        psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
     
    212212        // XXX use these to determine PAR[PM_PAR_I0]?
    213213        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    214         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     214        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    215215
    216216        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_PS1_DEV_1.c

    r31153 r31606  
    7070    psF32 xPos, yPos;
    7171    psF32 xErr, yErr;
    72     psF32 errMag, chisq;
     72    psF32 psfMagErr, chisq;
    7373
    7474    // let's write these out in S/N order
     
    103103            chisq = model->chisq;
    104104
    105             // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
    106             errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
     105            // need to determine the PSF photometry error: source->psfMagErr is the error on the 'best' model mag.
     106            psfMagErr = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
    107107        } else {
    108108            xPos = source->peak->xf;
     
    114114            axes.theta = NAN;
    115115            chisq = NAN;
    116             errMag = NAN;
     116            psfMagErr = NAN;
    117117        }
    118118
     
    128128        psMetadataAdd (row, PS_LIST_TAIL, "Y_PSF_SIG",        PS_DATA_F32, "Sigma in PSF y coordinate",                  yErr);
    129129        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG",     PS_DATA_F32, "PSF fit instrumental magnitude",             source->psfMag);
    130         psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        errMag);
     130        psMetadataAdd (row, PS_LIST_TAIL, "PSF_INST_MAG_SIG", PS_DATA_F32, "Sigma of PSF instrumental magnitude",        psfMagErr);
    131131        psMetadataAdd (row, PS_LIST_TAIL, "PEAK_FLUX_AS_MAG", PS_DATA_F32, "Peak flux expressed as magnitude",           peakMag);
    132132        psMetadataAdd (row, PS_LIST_TAIL, "SKY",              PS_DATA_F32, "Sky level",                                  source->sky);
     
    253253        // XXX use these to determine PAR[PM_PAR_I0]?
    254254        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    255         source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
     255        source->psfMagErr    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    256256        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    257         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     257        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->psfMagErr : NAN;
    258258
    259259        pmPSF_AxesToModel (PAR, axes);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_RAW.c

    r31153 r31606  
    110110        fprintf (f, "%7.1f %7.1f  %7.1f %8.4f  %7.4f %7.4f  ",
    111111                 PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], source->sky,
    112                  source->psfMag, source->errMag, dPos);
     112                 source->psfMag, source->psfMagErr, dPos);
    113113
    114114        for (j = 4; j < model->params->n; j++) {
     
    174174        fprintf (f, "%7.1f %7.1f  %7.1f %8.4f  %7.4f %7.4f  ",
    175175                 PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], source->sky,
    176                  source->extMag, source->errMag, dPos);
     176                 source->extMag, source->psfMagErr, dPos);
    177177
    178178        for (j = 4; j < model->params->n; j++) {
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_SMPDATA.c

    r31153 r31606  
    106106        psMetadataAdd (row, PS_LIST_TAIL, "Y_PIX",   PS_DATA_F32, "", yPos);
    107107        psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", PS_MIN (99.0, source->psfMag + ZERO_POINT));
    108         psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", PS_MIN (999, 1000*source->errMag));
     108        psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", PS_MIN (999, 1000*source->psfMagErr));
    109109        psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", PS_MIN (99.0, source->extMag + ZERO_POINT));
    110110        psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP",  PS_DATA_F32, "", PS_MIN (99.0, source->apMag + ZERO_POINT));
     
    194194        source->psfMag = psMetadataLookupF32 (&status, row, "MAG_RAW") - ZERO_POINT;
    195195        source->extMag = psMetadataLookupF32 (&status, row, "MAG_GAL") - ZERO_POINT;
    196         source->errMag = psMetadataLookupF32 (&status, row, "MAG_ERR") * 0.001;
     196        source->psfMagErr = psMetadataLookupF32 (&status, row, "MAG_ERR") * 0.001;
    197197        source->apMag  = psMetadataLookupF32 (&status, row, "MAG_AP")  - ZERO_POINT;
    198198
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceIO_SX.c

    r29004 r31606  
    8888        psLineAdd (line, "%11.3f", PAR[PM_PAR_YPOS]);
    8989        psLineAdd (line, "%9.4f",  source->psfMag);
    90         psLineAdd (line, "%9.4f",  source->errMag);
     90        psLineAdd (line, "%9.4f",  source->psfMagErr);
    9191        psLineAdd (line, "%13.4f", source->sky);
    9292        psLineAdd (line, "%9.2f",  axes.major);
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceMasks.h

    r31153 r31606  
    1414    PM_SOURCE_MODE_PSFSTAR          = 0x00000040, ///< Source used to define PSF model
    1515    PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
    16     PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sourcers
     16    PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sources
    1717    PM_SOURCE_MODE_EXTERNAL         = 0x00000200, ///< Source based on supplied input position
    1818    PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
     
    5151    PM_SOURCE_MODE2_ON_BURNTOOL      = 0x00000020, ///< > 25% of (PSF-weighted) pixels land on burntool
    5252    PM_SOURCE_MODE2_ON_CONVPOOR      = 0x00000040, ///< > 25% of (PSF-weighted) pixels land on convpoor
     53
     54    PM_SOURCE_MODE2_PASS1_SRC        = 0x00000080, ///< source detected in first pass analysis
    5355} pmSourceMode2;
    5456
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceMatch.c

    r29004 r31606  
    8888        pmSource *source = sources->data[i]; // Source of interest
    8989        if (!source || (source->mode & SOURCE_MASK) || !isfinite(source->psfMag) ||
    90             !isfinite(source->errMag) || source->psfMag > SOURCE_FAINTEST) {
     90            !isfinite(source->psfMagErr) || source->psfMag > SOURCE_FAINTEST) {
    9191            continue;
    9292        }
     
    102102        (*y)->data.F32[num] = ySrc;
    103103        (*mag)->data.F32[num] = source->psfMag;
    104         (*magErr)->data.F32[num] = source->errMag;
     104        (*magErr)->data.F32[num] = source->psfMagErr;
    105105        (*indices)->data.S32[num] = i;
    106106        num++;
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceMoments.c

    r31153 r31606  
    6666// if mode & EXTERNAL or mode2 & MATCHED, do not re-calculate the centroid (use peak as centroid)
    6767
    68 bool pmSourceMoments(pmSource *source, psF32 radius, psF32 sigma, psF32 minSN, psImageMaskType maskVal)
     68bool pmSourceMoments(pmSource *source, float radius, float sigma, float minSN, float minKronRadius, psImageMaskType maskVal)
    6969{
    7070    PS_ASSERT_PTR_NON_NULL(source, false);
     
    7474
    7575    // this function assumes the sky has been well-subtracted for the image
    76     psF32 sky = 0.0;
     76    float sky = 0.0;
    7777
    7878    if (source->moments == NULL) {
     
    8080    }
    8181
    82     psF32 Sum = 0.0;
    83     psF32 Var = 0.0;
    84     psF32 SumCore = 0.0;
    85     psF32 VarCore = 0.0;
    86     psF32 R2 = PS_SQR(radius);
    87     psF32 minSN2 = PS_SQR(minSN);
    88     psF32 rsigma2 = 0.5 / PS_SQR(sigma);
     82    float Sum = 0.0;
     83    float Var = 0.0;
     84    float SumCore = 0.0;
     85    float VarCore = 0.0;
     86    float R2 = PS_SQR(radius);
     87    float minSN2 = PS_SQR(minSN);
     88    float rsigma2 = 0.5 / PS_SQR(sigma);
    8989
    9090    // a note about coordinates: coordinates of objects throughout psphot refer to the primary
     
    109109    // Xn  = SUM (x - xc)^n * (z - sky)
    110110
    111     psF32 RF = 0.0;
    112     psF32 RH = 0.0;
    113     psF32 RS = 0.0;
    114     psF32 XX = 0.0;
    115     psF32 XY = 0.0;
    116     psF32 YY = 0.0;
    117     psF32 XXX = 0.0;
    118     psF32 XXY = 0.0;
    119     psF32 XYY = 0.0;
    120     psF32 YYY = 0.0;
    121     psF32 XXXX = 0.0;
    122     psF32 XXXY = 0.0;
    123     psF32 XXYY = 0.0;
    124     psF32 XYYY = 0.0;
    125     psF32 YYYY = 0.0;
     111    float RFW = 0.0;
     112    float RHW = 0.0;
     113
     114    float RF = 0.0;
     115    float RH = 0.0;
     116    float RS = 0.0;
     117    float XX = 0.0;
     118    float XY = 0.0;
     119    float YY = 0.0;
     120    float XXX = 0.0;
     121    float XXY = 0.0;
     122    float XYY = 0.0;
     123    float YYY = 0.0;
     124    float XXXX = 0.0;
     125    float XXXY = 0.0;
     126    float XXYY = 0.0;
     127    float XYYY = 0.0;
     128    float YYYY = 0.0;
    126129
    127130    Sum = 0.0;  // the second pass may include slightly different pixels, re-determine Sum
     131
     132    // float dX = source->moments->Mx - source->peak->xf;
     133    // float dY = source->moments->My - source->peak->yf;
     134    // float dR = hypot(dX, dY);
     135    // float Xo = (dR < 2.0) ? source->moments->Mx : source->peak->xf;
     136    // float Yo = (dR < 2.0) ? source->moments->My : source->peak->yf;
     137    float Xo = source->moments->Mx;
     138    float Yo = source->moments->My;
    128139
    129140    // center of mass in subimage.  Note: the calculation below uses pixel index, so we correct
    130141    // xCM, yCM from pixel coords to pixel index here.
    131     psF32 xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage
    132     psF32 yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage
     142    float xCM = Xo - 0.5 - source->pixels->col0; // coord of peak in subimage
     143    float yCM = Yo - 0.5 - source->pixels->row0; // coord of peak in subimage
    133144
    134145    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    135146
    136         psF32 yDiff = row - yCM;
     147        float yDiff = row - yCM;
    137148        if (fabs(yDiff) > radius) continue;
    138149
    139         psF32 *vPix = source->pixels->data.F32[row];
    140         psF32 *vWgt = source->variance->data.F32[row];
     150        float *vPix = source->pixels->data.F32[row];
     151        float *vWgt = source->variance->data.F32[row];
     152
    141153        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     154        // psImageMaskType  *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
    142155
    143156        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     
    151164            if (isnan(*vPix)) continue;
    152165
    153             psF32 xDiff = col - xCM;
     166            float xDiff = col - xCM;
    154167            if (fabs(xDiff) > radius) continue;
    155168
    156169            // radius is just a function of (xDiff, yDiff)
    157             psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     170            float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
    158171            if (r2 > R2) continue;
    159172
    160             psF32 fDiff = *vPix - sky;
    161             psF32 pDiff = fDiff;
    162             psF32 wDiff = *vWgt;
     173            float fDiff = *vPix - sky;
     174            float pDiff = fDiff;
     175            float wDiff = *vWgt;
    163176
    164177            // skip pixels below specified significance level.  this is allowed, but should be
     
    171184            // weighting over weights the sky for faint sources
    172185            if (sigma > 0.0) {
    173                 psF32 z = r2 * rsigma2;
     186                float z = r2 * rsigma2;
    174187                assert (z >= 0.0);
    175                 psF32 weight  = exp(-z);
     188                float weight  = exp(-z);
    176189
    177190                wDiff *= weight;
     
    182195
    183196            // Kron Flux uses the 1st radial moment (NOT Gaussian windowed?)
    184             psF32 r = sqrt(r2);
    185             psF32 rf = r * fDiff;
    186             psF32 rh = sqrt(r) * fDiff;
    187             psF32 rs = fDiff;
    188 
    189             psF32 x = xDiff * pDiff;
    190             psF32 y = yDiff * pDiff;
    191 
    192             psF32 xx = xDiff * x;
    193             psF32 xy = xDiff * y;
    194             psF32 yy = yDiff * y;
    195 
    196             psF32 xxx = xDiff * xx / r;
    197             psF32 xxy = xDiff * xy / r;
    198             psF32 xyy = xDiff * yy / r;
    199             psF32 yyy = yDiff * yy / r;
    200 
    201             psF32 xxxx = xDiff * xxx / r2;
    202             psF32 xxxy = xDiff * xxy / r2;
    203             psF32 xxyy = xDiff * xyy / r2;
    204             psF32 xyyy = xDiff * yyy / r2;
    205             psF32 yyyy = yDiff * yyy / r2;
     197            float r = sqrt(r2);
     198            float rf = r * fDiff;
     199            float rh = sqrt(r) * fDiff;
     200            float rs = fDiff;
     201
     202            float rfw = r * pDiff;
     203            float rhw = sqrt(r) * pDiff;
     204
     205            float x = xDiff * pDiff;
     206            float y = yDiff * pDiff;
     207
     208            float xx = xDiff * x;
     209            float xy = xDiff * y;
     210            float yy = yDiff * y;
     211
     212            float xxx = xDiff * xx / r;
     213            float xxy = xDiff * xy / r;
     214            float xyy = xDiff * yy / r;
     215            float yyy = yDiff * yy / r;
     216
     217            float xxxx = xDiff * xxx / r2;
     218            float xxxy = xDiff * xxy / r2;
     219            float xxyy = xDiff * xyy / r2;
     220            float xyyy = xDiff * yyy / r2;
     221            float yyyy = yDiff * yyy / r2;
    206222
    207223            RF  += rf;
    208224            RH  += rh;
    209225            RS  += rs;
     226
     227            RFW  += rfw;
     228            RHW  += rhw;
    210229
    211230            XX  += xx;
     
    244263    source->moments->Myyyy = YYYY/Sum;
    245264
    246     // Calculate the Kron magnitude (make this block optional?)
    247     float radKinner = 1.0*source->moments->Mrf;
    248     float radKron   = 2.5*source->moments->Mrf;
    249     float radKouter = 4.0*source->moments->Mrf;
     265    // if Mrf (first radial moment) is very small, we are getting into low-significance
     266    // territory.  saturate at minKronRadius.  conversely, if Mrf is > radius, we are clearly
     267    // making an error.  saturate at radius.
     268    float kronRefRadius = MIN(radius, MAX(minKronRadius, source->moments->Mrf));
     269
     270    float radKinner = 1.0*kronRefRadius;
     271    float radKron   = 2.5*kronRefRadius;
     272    float radKouter = 4.0*kronRefRadius;
    250273
    251274    int nKronPix = 0;
     
    259282    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    260283
    261         psF32 yDiff = row - yCM;
     284        float yDiff = row - yCM;
    262285        if (fabs(yDiff) > radKouter) continue;
    263286
    264         psF32 *vPix = source->pixels->data.F32[row];
    265         psF32 *vWgt = source->variance->data.F32[row];
     287        float *vPix = source->pixels->data.F32[row];
     288        float *vWgt = source->variance->data.F32[row];
     289
    266290        psImageMaskType  *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     291        // psImageMaskType  *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
    267292
    268293        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     
    276301            if (isnan(*vPix)) continue;
    277302
    278             psF32 xDiff = col - xCM;
     303            float xDiff = col - xCM;
    279304            if (fabs(xDiff) > radKouter) continue;
    280305
    281306            // radKron is just a function of (xDiff, yDiff)
    282             psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
    283 
    284             psF32 pDiff = *vPix - sky;
    285             psF32 wDiff = *vWgt;
     307            float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     308
     309            float pDiff = *vPix - sky;
     310            float wDiff = *vWgt;
    286311
    287312            // skip pixels below specified significance level.  this is allowed, but should be
     
    290315            if (PS_SQR(pDiff) < minSN2*wDiff) continue;
    291316
    292             psF32 r  = sqrt(r2);
     317            float r  = sqrt(r2);
    293318            if (r < radKron) {
    294319                Sum += pDiff;
     
    335360}
    336361
    337 bool pmSourceMomentsGetCentroid(pmSource *source, psF32 radius, psF32 sigma, psF32 minSN, psImageMaskType maskVal, float xGuess, float yGuess) {
     362bool pmSourceMomentsGetCentroid(pmSource *source, float radius, float sigma, float minSN, psImageMaskType maskVal, float xGuess, float yGuess) {
    338363
    339364    // First Pass: calculate the first moments (these are subtracted from the coordinates below)
     
    342367    // .. etc
    343368
    344     psF32 sky = 0.0;
    345 
    346     psF32 peakPixel = -PS_MAX_F32;
     369    float sky = 0.0;
     370
     371    float peakPixel = -PS_MAX_F32;
    347372    psS32 numPixels = 0;
    348     psF32 Sum = 0.0;
    349     psF32 Var = 0.0;
    350     psF32 X1 = 0.0;
    351     psF32 Y1 = 0.0;
    352     psF32 R2 = PS_SQR(radius);
    353     psF32 minSN2 = PS_SQR(minSN);
    354     psF32 rsigma2 = 0.5 / PS_SQR(sigma);
     373    float Sum = 0.0;
     374    float Var = 0.0;
     375    float X1 = 0.0;
     376    float Y1 = 0.0;
     377    float R2 = PS_SQR(radius);
     378    float minSN2 = PS_SQR(minSN);
     379    float rsigma2 = 0.5 / PS_SQR(sigma);
    355380
    356381    float xPeak = xGuess - source->pixels->col0; // coord of peak in subimage
     
    358383
    359384    // we are guaranteed to have a valid pixel and variance at this location (right? right?)
    360     // psF32 weightNorm = source->pixels->data.F32[yPeak][xPeak] / sqrt (source->variance->data.F32[yPeak][xPeak]);
     385    // float weightNorm = source->pixels->data.F32[yPeak][xPeak] / sqrt (source->variance->data.F32[yPeak][xPeak]);
    361386    // psAssert (isfinite(source->pixels->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
    362387    // psAssert (isfinite(source->variance->data.F32[yPeak][xPeak]), "peak must be on valid pixel");
     
    370395    for (psS32 row = 0; row < source->pixels->numRows ; row++) {
    371396
    372         psF32 yDiff = row + 0.5 - yPeak;
     397        float yDiff = row + 0.5 - yPeak;
    373398        if (fabs(yDiff) > radius) continue;
    374399
    375         psF32 *vPix = source->pixels->data.F32[row];
    376         psF32 *vWgt = source->variance->data.F32[row];
     400        float *vPix = source->pixels->data.F32[row];
     401        float *vWgt = source->variance->data.F32[row];
     402
    377403        psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[row];
     404        // psImageMaskType *vMsk = (source->maskView == NULL) ? NULL : source->maskView->data.PS_TYPE_IMAGE_MASK_DATA[row];
    378405
    379406        for (psS32 col = 0; col < source->pixels->numCols ; col++, vPix++, vWgt++) {
     
    387414            if (isnan(*vPix)) continue;
    388415
    389             psF32 xDiff = col + 0.5 - xPeak;
     416            float xDiff = col + 0.5 - xPeak;
    390417            if (fabs(xDiff) > radius) continue;
    391418
    392419            // radius is just a function of (xDiff, yDiff)
    393             psF32 r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
     420            float r2  = PS_SQR(xDiff) + PS_SQR(yDiff);
    394421            if (r2 > R2) continue;
    395422
    396             psF32 pDiff = *vPix - sky;
    397             psF32 wDiff = *vWgt;
     423            float pDiff = *vPix - sky;
     424            float wDiff = *vWgt;
    398425
    399426            // skip pixels below specified significance level.  for a PSFs, this
     
    408435            // weighting over weights the sky for faint sources
    409436            if (sigma > 0.0) {
    410                 psF32 z  = r2*rsigma2;
     437                float z  = r2*rsigma2;
    411438                assert (z >= 0.0);
    412                 psF32 weight  = exp(-z);
     439                float weight  = exp(-z);
    413440
    414441                wDiff *= weight;
     
    419446            Sum += pDiff;
    420447
    421             psF32 xWght = xDiff * pDiff;
    422             psF32 yWght = yDiff * pDiff;
     448            float xWght = xDiff * pDiff;
     449            float yWght = yDiff * pDiff;
    423450
    424451            X1  += xWght;
     
    477504    return true;
    478505}
     506
     507float pmSourceMinKronRadius(psArray *sources, float PSF_SN_LIM) {
     508
     509    psVector *radii = psVectorAllocEmpty(100, PS_TYPE_F32);
     510
     511    for (int i = 0; i < sources->n; i++) {
     512        pmSource *src = sources->data[i]; // Source of interest
     513        if (!src || !src->moments) {
     514            continue;
     515        }
     516
     517        if (src->mode & PM_SOURCE_MODE_BLEND) {
     518            continue;
     519        }
     520
     521        if (!src->moments->nPixels) continue;
     522
     523        if (src->moments->SN < PSF_SN_LIM) continue;
     524
     525        // XXX put in Mxx,Myy cut based on clump location
     526
     527        psVectorAppend(radii, src->moments->Mrf);
     528    }
     529
     530    // find the peak in this image
     531    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     532
     533    if (!psVectorStats (stats, radii, NULL, NULL, 0)) {
     534        psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
     535        psFree(stats);
     536        return NAN;
     537    }
     538
     539    float minRadius = stats->sampleMedian;
     540
     541    psFree(radii);
     542    psFree(stats);
     543    return minRadius;
     544}
     545
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceOutputs.c

    r31153 r31606  
    9898        outputs->xPos = PAR[PM_PAR_XPOS];
    9999        outputs->yPos = PAR[PM_PAR_YPOS];
    100         if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) {
     100        if ((source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) && !(source->mode & PM_SOURCE_MODE_EXTMODEL)) {
     101            // we only do non-linear PSF fits for non-extended objects
    101102            outputs->xErr = dPAR[PM_PAR_XPOS];
    102103            outputs->yErr = dPAR[PM_PAR_YPOS];
    103104        } else {
    104             outputs->xErr = fwhmMajor * source->errMag / 2.35;
    105             outputs->yErr = fwhmMinor * source->errMag / 2.35;
     105            outputs->xErr = fwhmMajor * source->psfMagErr / 2.35;
     106            outputs->yErr = fwhmMinor * source->psfMagErr / 2.35;
    106107        }
    107         if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
     108        if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXY]) && isfinite(PAR[PM_PAR_SYY])) {
    108109            axes = pmPSF_ModelToAxes (PAR, 20.0);
    109110            outputs->psfMajor = axes.major;
     
    125126            outputs->xPos = source->moments->Mx;
    126127            outputs->yPos = source->moments->My;
    127             outputs->xErr = fwhmMajor * source->errMag / 2.35;
    128             outputs->yErr = fwhmMinor * source->errMag / 2.35;
     128            outputs->xErr = fwhmMajor * source->psfMagErr / 2.35;
     129            outputs->yErr = fwhmMinor * source->psfMagErr / 2.35;
    129130        } else {
    130131            outputs->xPos = source->peak->xf;
  • branches/czw_branch/20110406/psModules/src/objects/pmSourcePhotometry.c

    r31153 r31606  
    8282   - apMag  : only if S/N > AP_MIN_SN
    8383   : is optionally corrected for curve-of-growth if:
    84    - the source is a STAR (PSF)
    8584   - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)
    8685   - psfMag : all sources with non-NULL modelPSF
    8786   : is optionally corrected for aperture residual if:
    88    - the source is a STAR (PSF)
    8987   - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
    90 
    9188   - extMag : all sources with non-NULL modelEXT
    9289**/
     
    10097
    10198    int status = false;
    102     bool isPSF;
    10399    float x, y;
    104     float rflux;
    105100    float SN;
    106     pmModel *model;
    107101
    108102    source->psfMag    = NAN;
    109103    source->extMag    = NAN;
    110     source->errMag    = NAN;
     104    source->psfMagErr = NAN;
    111105    source->apMag     = NAN;
    112106    source->apMagRaw  = NAN;
     
    114108    source->apFluxErr = NAN;
    115109
    116     // we must have a valid model
    117     // XXX allow aperture magnitudes for sources without a model
    118     model = pmSourceGetModel (&isPSF, source);
    119     if (model == NULL) {
    120         psTrace ("psModules.objects", 3, "fail mag : no valid model");
     110    // XXXXXX review:
     111    // Select the 'best' model -- this is used for PSF_QF,_PERFECT & ???. isPSF is true if this
     112    // object is a PSF (not extended).  We must have a valid model.  XXX NOTE: allow aperture
     113    // magnitudes for sources without a model
     114
     115    // select the psf model
     116    pmModel *modelPSF = source->modelPSF;
     117    if (modelPSF == NULL) {
     118        psTrace ("psModules.objects", 3, "fail mag : no valid PSF model");
    121119        return false;
    122120    }
    123121
    124     // XXX handle negative flux, low-significance
    125     if (model->dparams->data.F32[PM_PAR_I0] > 0) {
    126         SN = fabs(model->params->data.F32[PM_PAR_I0] / model->dparams->data.F32[PM_PAR_I0]);
    127         source->errMag = 1.0 / SN;
     122    // get the error on the PSF model magnitude
     123    if (modelPSF->dparams->data.F32[PM_PAR_I0] > 0) {
     124        SN = fabs(modelPSF->params->data.F32[PM_PAR_I0] / modelPSF->dparams->data.F32[PM_PAR_I0]);
     125        source->psfMagErr = 1.0 / SN;
    128126    } else {
    129127        SN = NAN;
    130         source->errMag = NAN;
    131     }
    132     x = model->params->data.F32[PM_PAR_XPOS];
    133     y = model->params->data.F32[PM_PAR_YPOS];
     128        source->psfMagErr = NAN;
     129    }
     130    // the source position is used to recenter the aperture for ap photometry
     131    x = modelPSF->params->data.F32[PM_PAR_XPOS];
     132    y = modelPSF->params->data.F32[PM_PAR_YPOS];
    134133
    135134    // measure PSF model photometry
    136     // XXX TEST: do not use flux scale
    137     // XXX NOTE: turn this back on?
    138     if (0 && psf->FluxScale) {
    139         // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    140         double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y);
    141         psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
    142         psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
    143         source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0];
    144         source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0];
    145         source->psfMag = -2.5*log10(source->psfFlux);
    146     } else {
    147         status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF);
    148         source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]);
    149     }
     135    status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, modelPSF);
     136    source->psfFluxErr = source->psfFlux * source->psfMagErr;
     137
     138# if (0)
     139    // XXX NOTE: old code to use the flux scale.  test & turn this back on?  if so, need to save with psf model
     140    // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
     141    double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y);
     142    psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);
     143    psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);
     144    source->psfFlux = fluxScale * modelPSF->params->data.F32[PM_PAR_I0];
     145    source->psfFluxErr = fluxScale * modelPSF->dparams->data.F32[PM_PAR_I0];
     146    source->psfMag = -2.5*log10(source->psfFlux);
     147# endif
    150148
    151149    if (mode == PM_SOURCE_PHOT_PSFONLY) {
     
    153151    }
    154152
     153    // get the EXT model photometry (all EXT models)
    155154    // if we have a collection of model fits, check if one of them is a pointer to modelEXT
    156155    if (source->modelFits) {
     
    173172    }
    174173
    175     // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
    176     // XXX add a flag for "ap_mag is corrected?"
    177     if ((mode & PM_SOURCE_PHOT_APCORR) && isPSF && psf && psf->ApTrend) {
     174    // Correct psfMag to match aperture magnitude system (NOTE : Growth curve is already applied to ApTrend)
     175    if ((mode & PM_SOURCE_PHOT_APCORR) && psf && psf->ApTrend) {
    178176        // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center
    179177        double apTrend = pmTrend2DEval (psf->ApTrend, (float)source->peak->x, (float)source->peak->y);
    180178        source->psfMag += apTrend;
    181     }
    182 
    183     // measure the contribution of included pixels
     179        source->psfFlux *= pow(10.0, -0.4*apTrend);
     180        source->psfFluxErr *= pow(10.0, -0.4*apTrend);
     181    }
     182
     183    // measure the contribution of included pixels to the PSF model fit
    184184    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    185         pmSourcePixelWeight (source, model, source->maskObj, maskVal, radius);
     185        pmSourcePixelWeight (source, modelPSF, source->maskObj, maskVal, radius);
    186186    }
    187187
     
    217217        y += dy;
    218218
    219         if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy,
    220                               NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) {
     219        // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_LANCZOS2)) {
     220        // if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BIQUADRATIC)) {
     221        if (!psImageShiftMask(&flux, &mask, source->pixels, source->maskObj, maskVal, dx, dy, NAN, 0xff, PS_INTERPOLATE_BILINEAR)) {
    221222            // Not much we can do about it
    222223            psErrorClear();
     
    232233
    233234    // measure object aperture photometry
    234     status = pmSourcePhotometryAperSource (source, model, flux, variance, mask, maskVal);
     235    status = pmSourcePhotometryAperSource (source, modelPSF, flux, variance, mask, maskVal);
    235236    if (!status) {
    236237        psTrace ("psModules.objects", 3, "fail mag : bad Ap Mag");
     
    241242    // detection limits (esp near bright neighbors)
    242243    source->apMag = source->apMagRaw;
    243     if (isfinite (source->apMag) && isPSF && psf) {
     244    if (isfinite (source->apMag) && psf) {
    244245        if (psf->growth && (mode & PM_SOURCE_PHOT_GROWTH)) {
    245             source->apMag = source->apMagRaw + pmGrowthCurveCorrect (psf->growth, source->apRadius);
    246             // XXX correct the apFlux?
    247         }
    248         if (mode & PM_SOURCE_PHOT_APCORR) {
    249             // XXX this should be removed -- we no longer fit for the 'sky bias'
    250             // XXX is this happening???
    251             rflux   = pow (10.0, 0.4*source->psfMag);
    252             psAssert (psf->skyBias == 0.0, "sky bias not 0");
    253             psAssert (psf->skySat == 0.0, "sky sat not 0");
    254             source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux;
     246            float apOffset = pmGrowthCurveCorrect (psf->growth, source->apRadius);
     247            source->apMag = source->apMagRaw + apOffset;
     248            source->apFlux *= pow(10.0, -0.4*apOffset);
     249            source->apFluxErr *= pow(10.0, -0.4*apOffset);
    255250        }
    256251    }
     
    309304
    310305    bool status;
    311     status = pmSourcePhotometryAper(&source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
    312 
     306    int nPix = 0;
     307    status = pmSourcePhotometryAper(&nPix, &source->apMagRaw, &source->apFlux, &source->apFluxErr, model, image, variance, mask, maskVal);
     308    if (status) {
     309        source->mode |= PM_SOURCE_MODE_AP_MAGS;
     310    }
    313311    return status;
    314312}
    315313
    316314// return source aperture magnitude
    317 bool pmSourcePhotometryAper (float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
     315bool pmSourcePhotometryAper (int *nPixOut, float *apMag, float *apFluxOut, float *apFluxErr, pmModel *model, psImage *image, psImage *variance, psImage *mask, psImageMaskType maskVal)
    318316{
    319317    PS_ASSERT_PTR_NON_NULL(apMag, false);
     
    328326    float apFlux = 0;
    329327    float apFluxVar = 0;
     328    int nPix = 0;
    330329
    331330    if (DO_SKY) {
     
    345344            apFlux += imData[iy][ix] - sky;
    346345            apFluxVar += varData[iy][ix];
    347         }
    348     }
     346            nPix ++;
     347        }
     348    }
     349   
    349350    if (apFluxOut) *apFluxOut = apFlux;
    350351    if (apFluxErr) *apFluxErr = sqrt(fabs(apFluxVar));
     352    if (nPixOut) *nPixOut = nPix;
    351353
    352354    if (apFlux <= 0) {
     
    412414    psImageMaskType maskBad = maskVal;
    413415    maskBad &= ~maskSuspect;
     416
     417    psImageMaskType maskPoor = maskVal | maskSuspect;
    414418
    415419    // measure modelSum and validSum.  this function is applied to a sources' subimage.  the
     
    446450
    447451            // count pixels which are masked with an mask bit (bad or poor)
    448             if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskVal)) {
     452            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[my][mx] & maskPoor)) {
    449453                notPoorSum += value;
    450454            }
     
    487491
    488492    if (isfinite(source->pixWeightNotBad) && isfinite(source->pixWeightNotPoor)) {
    489         psAssert (source->pixWeightNotBad <= source->pixWeightNotPoor, "error: all bad pixels should also be poor");
     493        psAssert (source->pixWeightNotPoor <= source->pixWeightNotBad, "error: all bad pixels should also be poor");
    490494    }
    491495
  • branches/czw_branch/20110406/psModules/src/objects/pmSourcePhotometry.h

    r31153 r31606  
    4545
    4646bool pmSourcePhotometryAper(
     47    int *nPixOut,
    4748    float *apMag,
    4849    float *apFluxOut,
  • branches/czw_branch/20110406/psModules/src/objects/pmSourceUtils.h

    r14652 r31606  
    3838
    3939/// @}
    40 # endif /* PM_MODEL_CLASS_H */
     40# endif /* PM_SOURCE_UTILS_H */
  • branches/czw_branch/20110406/psModules/src/psmodules.h

    r30623 r31606  
    148148#include <pmModelUtils.h>
    149149#include <pmSourcePhotometry.h>
     150#include <pmGrowthCurveGenerate.h>
    150151#include <pmSourceVisual.h>
    151152#include <pmSourceMatch.h>
  • branches/czw_branch/20110406/psModules/test/objects/tap_pmSource.c

    r31153 r31606  
    9191        ok(isnan(src->psfMag), "pmSourceAlloc() pmSource->psfMag correctly");
    9292        ok(isnan(src->extMag), "pmSourceAlloc() pmSource->extMag correctly");
    93         ok(isnan(src->errMag), "pmSourceAlloc() pmSource->errMag correctly");
     93        ok(isnan(src->psfMagErr), "pmSourceAlloc() pmSource->psfMagErr correctly");
    9494        ok(isnan(src->apMag), "pmSourceAlloc() pmSource->apMag correctly");
    9595        ok(isnan(src->sky), "pmSourceAlloc() pmSource->sky correctly");
  • branches/czw_branch/20110406/psModules/test/objects/tap_pmSourceIO_PS1_DEV_0.c

    r21223 r31606  
    167167            model->dparams->data.F32[PM_PAR_YPOS] = TEST_BASE_Y_ERR + (float) i;
    168168            src->psfMag = TEST_BASE_PSF_MAG + (float) i;
    169             src->errMag = TEST_BASE_ERR_MAG + (float) i;
     169            src->psfMagErr = TEST_BASE_ERR_MAG + (float) i;
    170170            src->peak->flux = TEST_BASE_PEAK_FLUX + (float) i;
    171171            src->sky = TEST_BASE_SKY + (float) i;
     
    215215             ok(src->psfMag == (TEST_BASE_PSF_MAG + (float) i), "pmSourcesRead_PS1_DEV_0() set src->psfMag correctly (is %.2f, should be %.2f)",
    216216                src->psfMag, (TEST_BASE_PSF_MAG + (float) i));
    217              ok(src->errMag == (TEST_BASE_ERR_MAG + (float) i), "pmSourcesRead_PS1_DEV_0() set src->errMag correctly (is %.2f, should be %.2f)",
    218                 src->errMag, (TEST_BASE_ERR_MAG + (float) i));
     217             ok(src->psfMagErr == (TEST_BASE_ERR_MAG + (float) i), "pmSourcesRead_PS1_DEV_0() set src->psfMagErr correctly (is %.2f, should be %.2f)",
     218                src->psfMagErr, (TEST_BASE_ERR_MAG + (float) i));
    219219
    220220             // XXX: Source code always sets src->modelPSF.  Is that right?
  • branches/czw_branch/20110406/psModules/test/objects/tap_pmSourceIO_PS1_DEV_1.c

    r24852 r31606  
    196196            model->dparams->data.F32[PM_PAR_YPOS] = TEST_BASE_Y_ERR + (float) i;
    197197            src->psfMag = TEST_BASE_PSF_MAG + (float) i;
    198             src->errMag = TEST_BASE_ERR_MAG + (float) i;
     198            src->psfMagErr = TEST_BASE_ERR_MAG + (float) i;
    199199            src->peak->flux = TEST_BASE_PEAK_FLUX + (float) i;
    200200            src->sky = TEST_BASE_SKY + (float) i;
     
    203203            sources->data[i] = (psPtr *) src;
    204204            src->psfMag = TEST_BASE_PSF_MAG + (float) i;
    205             src->errMag = TEST_BASE_ERR_MAG + (float) i;
     205            src->psfMagErr = TEST_BASE_ERR_MAG + (float) i;
    206206            src->sky = TEST_BASE_SKY + (float) i;
    207207            src->skyErr = TEST_BASE_SKY_ERR + (float) i;
     
    280280             ok(src->psfMag == (TEST_BASE_PSF_MAG + (float) i), "pmSourcesRead_PS1_DEV_1() set src->psfMag correctly (is %.2f, should be %.2f)",
    281281                src->psfMag, (TEST_BASE_PSF_MAG + (float) i));
    282              ok(src->errMag == (TEST_BASE_ERR_MAG + (float) i), "pmSourcesRead_PS1_DEV_1() set src->errMag correctly (is %.2f, should be %.2f)",
    283                 src->errMag, (TEST_BASE_ERR_MAG + (float) i));
     282             ok(src->psfMagErr == (TEST_BASE_ERR_MAG + (float) i), "pmSourcesRead_PS1_DEV_1() set src->psfMagErr correctly (is %.2f, should be %.2f)",
     283                src->psfMagErr, (TEST_BASE_ERR_MAG + (float) i));
    284284
    285285             // XXX: Source code always sets src->modelPSF.  Is that right?
  • branches/czw_branch/20110406/psModules/test/objects/tap_pmSourceIO_SMPDATA.c

    r21223 r31606  
    167167            model->dparams->data.F32[PM_PAR_YPOS] = TEST_BASE_Y_ERR + (float) i;
    168168            src->psfMag = TEST_BASE_PSF_MAG + (float) i;
    169             src->errMag = TEST_BASE_ERR_MAG + (float) i;
     169            src->psfMagErr = TEST_BASE_ERR_MAG + (float) i;
    170170            src->peak->flux = TEST_BASE_PEAK_FLUX + (float) i;
    171171            src->sky = TEST_BASE_SKY + (float) i;
     
    226226                src->psfMag, (TEST_BASE_PSF_MAG + (float) i));
    227227             float tmpF =  0.001 * PS_MIN(999, (1000 * (TEST_BASE_ERR_MAG + (float) i)));
    228              ok(src->errMag == tmpF, "pmSourcesRead_SMPDATA() set src->errMag correctly (is %.2f, should be %.2f)",
    229                 src->errMag, tmpF);
     228             ok(src->psfMagErr == tmpF, "pmSourcesRead_SMPDATA() set src->psfMagErr correctly (is %.2f, should be %.2f)",
     229                src->psfMagErr, tmpF);
    230230             tmpF = PS_MIN(99.0, (TEST_BASE_EXT_MAG + ZERO_POINT)) - ZERO_POINT;
    231231             ok(src->extMag == tmpF, "pmSourcesRead_SMPDATA() set src->extMag correctly (is %.2f, should be %.2f)",
  • branches/czw_branch/20110406/psModules/test/objects/tap_pmSourcePhotometry.c

    r25754 r31606  
    103103    ok_float_tol(source->psfMag, fitMag, 0.0002, "source fitMag is %f", source->psfMag);
    104104    ok_float_tol(source->apMag,  apMag, 0.0002, "source apMag is %f", source->apMag);
    105     ok_float(source->errMag,   0.001, "source errMag is %f", source->errMag);
     105    ok_float(source->psfMagErr,   0.001, "source psfMagErr is %f", source->psfMagErr);
    106106    float refMag = source->apMag;
    107107
  • branches/czw_branch/20110406/psastro/src/psastroConvert.c

    r31434 r31606  
    133133        pmSource *source = sources->data[n];
    134134
    135         psTrace ("psastro", 6, "mag: %f +/- %f, mode: %x, skip: %x\n", source->psfMag, source->errMag, source->mode, skip);
     135        psTrace ("psastro", 6, "mag: %f +/- %f, mode: %x, skip: %x\n", source->psfMag, source->psfMagErr, source->mode, skip);
    136136
    137137        if (source->mode & skip) {
     
    191191        obj->pix->yErr = dPAR[PM_PAR_YPOS];
    192192        obj->Mag = source->psfMag;
    193         obj->dMag = source->errMag;
     193        obj->dMag = source->psfMagErr;
    194194
    195195        // XXX do we have the information giving the readout and cell offset?
  • branches/czw_branch/20110406/psconfig/psbuild

    r31068 r31606  
    386386    if (@ARGV != 2) { die "USAGE: psbuild -bootstrap (install_dir)\n"; }
    387387    $psconfdir = $ARGV[1];
     388    die "Target directory must be absolute, not relative: $psconfdir\n" unless $psconfdir =~ m|^/|;
    388389
    389390    # copy psconfig.csh and psconfig.bash to psconfdir
  • branches/czw_branch/20110406/psconfig/tagsets/ipp-3.0.libs

    r31162 r31606  
    3030lib libpthread           NONE           NONE   NONE                     NONE             N NONE NONE NONE
    3131lib libncurses           curses,termcap NONE   ncurses-5.6.tar.gz       ncurses-5.6      N NONE NONE NONE
    32 # XXX : temp for buildtest
    33 # lib libreadline          NONE           NONE   readline-5.2-p14.tar.gz  readline-5.2-p14 Y NONE NONE NONE
     32lib libreadline          NONE           NONE   readline-5.2-p14.tar.gz  readline-5.2-p14 Y NONE NONE NONE
    3433lib libz                 NONE           NONE   zlib-1.2.3.tar.gz        zlib-1.2.3       N --shared NONE NONE
    3534lib libpng               NONE           NONE   libpng-1.2.15.tar.gz     libpng-1.2.15    N NONE NONE NONE
  • branches/czw_branch/20110406/psphot

  • branches/czw_branch/20110406/psphot/src/Makefile.am

    r31154 r31606  
    167167        psphotSourcePlots.c            \
    168168        psphotRadialPlot.c             \
     169        psphotKronMasked.c             \
    169170        psphotDeblendSatstars.c        \
    170171        psphotMosaicSubimage.c         \
  • branches/czw_branch/20110406/psphot/src/psphot.h

    r31154 r31606  
    149149bool            psphotPSFstats (pmReadout *readout, pmPSF *psf);
    150150bool            psphotMomentsStats (pmReadout *readout, psArray *sources);
     151
     152bool            psphotKronMasked (pmConfig *config, const pmFPAview *view, const char *filerule);
     153bool            psphotKronMaskedReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf);
    151154
    152155// in psphotGuessModel.c
     
    310313
    311314bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf);
    312 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf);
     315bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources);
    313316bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psImageMaskType maskVal, psImageMaskType markVal);
    314317
  • branches/czw_branch/20110406/psphot/src/psphotApResid.c

    r31154 r31606  
    11# include "psphotInternal.h"
    2 // # define DEBUG
     2# define DEBUG
    33
    44# define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; }
     
    206206
    207207        // XXX make this user-configurable?
    208         if (source->errMag > 0.01) continue;
     208        if (source->psfMagErr > 0.01) continue;
    209209
    210210        // aperture residual for this source
     
    222222                 source->peak->xf, source->peak->yf,
    223223                 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS],
    224                  source->psfMag, source->apMag, source->errMag,
     224                 source->psfMag, source->apMag, source->psfMagErr,
    225225                 source->modelPSF->params->data.F32[PM_PAR_I0],
    226226                 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY],
     
    228228# endif
    229229        if (!isfinite(source->psfMag)) psAbort ("nan in psfMag");
    230         if (!isfinite(source->errMag)) psAbort ("nan in errMag");
     230        if (!isfinite(source->psfMagErr)) psAbort ("nan in psfMagErr");
    231231        if (!isfinite(source->apMag)) psAbort ("nan in apMag");
    232232        if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos");
     
    234234
    235235        psVectorAppend (mag, source->psfMag);
    236         psVectorAppend (dMag,source->errMag);
     236        psVectorAppend (dMag,source->psfMagErr);
    237237        psVectorAppend (apResid, dap);
    238238        psVectorAppend (xPos, model->params->data.F32[PM_PAR_XPOS]);
     
    328328    psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_META_REPLACE, "ap residual scatter", psf->dApResid);
    329329    psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_META_REPLACE, "number of apresid stars", psf->nApResid);
    330     psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_META_REPLACE, "aperture loss (mag)", psf->growth ? psf->growth->apLoss : NAN);
     330
     331    // curve-of-growth offset
     332    if (psf->growth) {
     333        float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA");
     334        if (!status) {
     335            gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA");
     336        }
     337        float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE");
     338        float PSF_APERTURE = (int)(apScale*gaussSigma);
     339       
     340        float offset = pmGrowthCurveCorrect (psf->growth, PSF_APERTURE);
     341        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_META_REPLACE, "aperture loss (mag)", psf->growth->apLoss);
     342        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APREFOFF", PS_META_REPLACE, "offset to ref aperture", offset);
     343    } else {
     344        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS",   PS_META_REPLACE, "aperture loss (mag)", NAN);
     345        psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APREFOFF", PS_META_REPLACE, "offset to ref aperture", NAN);
     346    }
    331347
    332348    psLogMsg ("psphot.apresid", PS_LOG_DETAIL, "aperture residual: %f +/- %f\n", psf->ApResid, psf->dApResid);
  • branches/czw_branch/20110406/psphot/src/psphotBlendFit.c

    r31154 r31606  
    242242        if (source->mode &  PM_SOURCE_MODE_PAIR) continue;
    243243
     244        // do not include MOMENTS_FAILURES in the fit
     245        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     246
    244247        // limit selection to some SN limit
    245248        if (sqrt(source->peak->detValue) < FIT_SN_LIM) continue;
     
    280283        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    281284            if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) {
    282                 source->type = PM_SOURCE_TYPE_EXTENDED;
    283285                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
    284286                Next ++;
    285                 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    286287                continue;
    287288            }
     
    291292                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
    292293                Npsf ++;
    293                 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    294294                continue;
    295295            }
  • branches/czw_branch/20110406/psphot/src/psphotChoosePSF.c

    r31154 r31606  
    350350
    351351    // build curve-of-growth vector for this psf
    352     if (!psphotMakeGrowthCurve (readout, recipe, try->psf)) {
     352    if (!psphotMakeGrowthCurve (readout, recipe, try->psf, try->sources)) {
    353353        psError(PSPHOT_ERR_PSF, false, "Unable to construct flux scale for PSF");
    354354        psFree (models);
  • branches/czw_branch/20110406/psphot/src/psphotEfficiency.c

    r30560 r31606  
    400400                source->type = PM_SOURCE_TYPE_STAR;
    401401
     402                source->modelPSF->fitRadius = sourceRadius;
     403                source->apRadius = sourceRadius;
     404
    402405                numFound++;
    403406                psArrayAdd(sources, sources->n, source);
     
    468471                    source->modelPSF->params->data.F32[PM_PAR_XPOS],
    469472                    source->modelPSF->params->data.F32[PM_PAR_YPOS],
    470                     magRef, source->psfMag, source->errMag);
     473                    magRef, source->psfMag, source->psfMagErr);
    471474#endif
    472475            magDiff->data.F32[j] = source->psfMag - magRef;
    473             magErr->data.F32[j] = source->errMag;
     476            magErr->data.F32[j] = source->psfMagErr;
    474477        }
    475478        magDiff->n = sources->n;
  • branches/czw_branch/20110406/psphot/src/psphotExtendedSourceFits.c

    r31154 r31606  
    333333        // this uses the footprint to judge both radius and aperture?
    334334        // XXX save the psf-based moments for output
    335         if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) {
     335        if (!pmSourceMoments (source, radius, 0.0, 0.0, 0.0, maskVal)) {
    336336            fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf);
    337337            // subtract the best fit from the object, leave local sky
     
    379379          assert (status);
    380380
    381           // fprintf (stderr, "xfit: %f, %f : %f\n", source->peak->xf, source->peak->yf, source->peak->SN);
    382 
    383381          // limit selection to some SN limit
    384           assert (source->peak); // how can a source not have a peak?
     382          // assert (source->peak); // how can a source not have a peak?
    385383          if (sqrt(source->peak->detValue) < SNlim) {
    386384              Nfaint ++;
  • branches/czw_branch/20110406/psphot/src/psphotFitSourcesLinear.c

    r31154 r31606  
    137137        if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
    138138
     139        // do not include MOMENTS_FAILURES in the fit
     140        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
     141
    139142        // XXX count saturated stars
    140143        if (source->mode & PM_SOURCE_MODE_SATSTAR) {
     
    164167
    165168        // check the integral of the model : is it large enough?
     169        // apply mask?
    166170        float modelSum = 0.0;
     171        float maskedSum = 0.0;
    167172        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
    168173            for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
    169174                modelSum += source->modelFlux->data.F32[iy][ix];
     175                if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue;
     176                maskedSum += source->modelFlux->data.F32[iy][ix];
    170177            }
    171178        }
    172179        if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
    173         // if (modelSum < 0.01) continue; // skip sources with no model constraint (somewhat arbitrary limit)
    174180        if (modelSum < 0.8) {
    175             fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",
    176                      source->peak->xf, source->peak->yf, modelSum, source->peak->rawFlux);
     181            fprintf (stderr, "low-sig model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
     182                     source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
    177183        }
    178 
    179         pmModel *model = pmSourceGetModel (NULL, source);
     184        if (maskedSum < 0.5) {
     185            fprintf (stderr, "worrying model @ %f, %f (%f masked sum, %f sum, %f peak)\n",
     186                     source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux);
     187        }
     188
     189        bool isPSF = false;
     190        pmModel *model = pmSourceGetModel (&isPSF, source);
    180191
    181192        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    182193        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal);
    183194
    184         source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
     195        // we call this function multiple times. for the first time, we have only PSF models for all objects
     196        // the second time has extended sources.  If we ever fit the PSF model, we should raise this bit
     197        source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
     198        if (isPSF) {
     199            source->mode |= PM_SOURCE_MODE_PSFMODEL;
     200        }           
     201       
    185202        psArrayAdd (fitSources, 100, source);
    186203    }
     
    260277        }
    261278    }
     279
     280# if (0)
     281    static int npass = 0;
     282    char name[128];
     283    FILE *f1 = NULL;
     284    int fd = -1;
     285
     286    snprintf (name, 128, "sparse.Aij.%02d.dat", npass);
     287    f1 = fopen (name, "w");
     288    psAssert (f1, "failed to open file\n");
     289    fd = fileno (f1);
     290    p_psVectorPrint (fd, sparse->Aij, "Aij");
     291    fclose (f1);
     292
     293    snprintf (name, 128, "sparse.Bfj.%02d.dat", npass);
     294    f1 = fopen (name, "w");
     295    psAssert (f1, "failed to open file\n");
     296    fd = fileno (f1);
     297    p_psVectorPrint (fd, sparse->Bfj, "Bfj");
     298    fclose (f1);
     299
     300    snprintf (name, 128, "sparse.Qii.%02d.dat", npass);
     301    f1 = fopen (name, "w");
     302    psAssert (f1, "failed to open file\n");
     303    fd = fileno (f1);
     304    p_psVectorPrint (fd, sparse->Qii, "Qii");
     305    fclose (f1);
     306    npass ++;
     307# endif
    262308
    263309    psSparseResort (sparse);
  • branches/czw_branch/20110406/psphot/src/psphotFitSourcesLinearStack.c

    r31154 r31606  
    6969            if (!pmSourceCacheModel (source, maskVal)) continue;
    7070          }
     71
     72          // check the integral of the model : is it large enough?
     73          float modelSum = 0.0;
     74          for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     75              for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
     76                  modelSum += source->modelFlux->data.F32[iy][ix];
     77              }
     78          }
     79          if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit)
     80          if (modelSum < 0.8) {
     81              fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",
     82                       source->peak->xf, source->peak->yf, modelSum, source->peak->rawFlux);
     83          }
    7184
    7285          source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
  • branches/czw_branch/20110406/psphot/src/psphotGuessModels.c

    r31154 r31606  
    160160        pmSource *source = sources->data[i];
    161161
    162         if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {
    163             fprintf (stderr, "moment failure\n");
    164         }
    165 
    166162        // this is used to mark sources for which the model is measured. We check later that
    167163        // all are used.
     
    169165
    170166        // skip non-astronomical objects (very likely defects)
     167        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
    171168        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
    172169        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     
    196193        }
    197194
     195# if (0)
    198196        if (source->mode & PM_SOURCE_MODE_SATSTAR) {
    199197            fprintf (stderr, "satstar: %f,%f vs %f,%f : %c\n",
     
    202200                     (useMoments ? 'T' : 'F'));
    203201        }
     202# endif
    204203
    205204        // set PSF parameters for this model (apply 2D shape model to coordinates Xo, Yo)
  • branches/czw_branch/20110406/psphot/src/psphotLoadSRCTEXT.c

    r31154 r31606  
    5252
    5353            // NOTE: most of these values are irrelevant for loaded source positions
    54             source->seq       = 0;
     54            source->seq       = source->id;
    5555            PAR[PM_PAR_XPOS]  = X;
    5656            PAR[PM_PAR_YPOS]  = Y;
     
    6767
    6868            source->psfMag    = 0.0;
    69             source->errMag    = 0.0;
     69            source->psfMagErr    = 0.0;
    7070            source->apMag     = 0.0;
    7171
  • branches/czw_branch/20110406/psphot/src/psphotMagnitudes.c

    r31154 r31606  
    167167        pmSource *source = (pmSource *) sources->data[i];
    168168
     169        bool saveTest = false;
     170        psImage *testImage = NULL;
     171# if (0)
     172        if ((fabs(source->peak->xf-3518) < 5) && (fabs(source->peak->yf-3178) < 5)) {
     173            saveTest = true;
     174            psRegion subregion = psRegionSet (source->peak->xf - 200, source->peak->xf + 200, source->peak->yf - 200, source->peak->yf + 200);
     175            testImage = psImageSubset ((psImage *) source->pixels->parent, subregion);
     176        }
     177# endif
     178
     179        if (saveTest) {
     180            psphotSaveImage(NULL, testImage, "test.image.1.fits");
     181        }
     182
    169183        // replace object in image
    170184        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
     
    172186        }
    173187
     188        if (saveTest) {
     189            psphotSaveImage(NULL, testImage, "test.image.2.fits");
     190        }
     191
     192        float xPos = source->peak->xf;
     193        float yPos = source->peak->yf;
     194
     195        pmModel *model = source->modelPSF;
     196        if (model) {
     197            xPos = model->params->data.F32[PM_PAR_XPOS];
     198            yPos = model->params->data.F32[PM_PAR_YPOS];
     199        } else {
     200            bool useMoments = pmSourcePositionUseMoments(source);
     201            if (useMoments) {
     202                xPos = source->moments->Mx;
     203                yPos = source->moments->My;
     204            }
     205        }
     206
    174207        // clear the mask bit and set the circular mask pixels
    175208        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
    176         psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);
     209        psImageKeepCircle (source->maskObj, xPos, yPos, source->apRadius, "OR", markVal);
    177210
    178211        status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius);
    179         if (status && isfinite(source->apMag)) Nap ++;
     212        if (status && isfinite(source->apFlux)) {
     213            Nap ++;
     214        } else {
     215            fprintf (stderr, "failed to measure mag for source @ %f,%f\n", source->peak->xf, source->peak->yf);
     216        }
    180217
    181218        // clear the mask bit
     
    185222        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    186223
     224        if (saveTest) {
     225            psphotSaveImage(NULL, testImage, "test.image.3.fits");
     226        }
     227
    187228        if (backModel) {
    188229            psAssert (binning, "if backModel is defined, so should binning be");
    189             source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
     230            source->sky = psImageUnbinPixel(xPos, yPos, backModel->image, binning);
    190231            if (isnan(source->sky) && false) {
    191232                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky");
     
    197238        if (backStdev) {
    198239            psAssert (binning, "if backStdev is defined, so should binning be");
    199             source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
     240            source->skyErr = psImageUnbinPixel(xPos, yPos, backStdev->image, binning);
    200241            if (isnan(source->skyErr) && false) {
    201242                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr");
  • branches/czw_branch/20110406/psphot/src/psphotMakeGrowthCurve.c

    r31154 r31606  
    11# include "psphotInternal.h"
    22
    3 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf) {
     3bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources) {
    44
    55    bool status;
     
    2222
    2323    // measure the aperture loss as a function of radius for PSF
    24     bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH");
    2524    float REF_RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_REF_RADIUS");
    2625    float PSF_FIT_PAD   = psMetadataLookupF32 (&status, recipe, "PSF_FIT_PADDING");
     26   
     27    float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA");
     28    if (!status) {
     29        gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA");
     30    }
     31    float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE");
     32    float PSF_APERTURE = (int)(apScale*gaussSigma);
    2733
    2834    psf->growth = pmGrowthCurveAlloc (PSF_FIT_PAD, 100.0, REF_RADIUS);
    2935
    30     if (!pmGrowthCurveGenerate (readout, psf, IGNORE_GROWTH, maskVal, markVal)) {
    31         psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections");
    32         psFree(psf->growth); psf->growth = NULL;
    33         return false;
     36    bool GROWTH_FROM_SOURCES = psMetadataLookupBool (&status, recipe, "GROWTH_FROM_SOURCES");
     37    if (!status) GROWTH_FROM_SOURCES = false;
     38
     39    if (GROWTH_FROM_SOURCES) {
     40        bool INTERPOLATE_AP = psMetadataLookupBool (&status, recipe, "INTERPOLATE_AP");
     41        if (!pmGrowthCurveGenerateFromSources (readout, psf, sources, INTERPOLATE_AP, maskVal, markVal)) {
     42            psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections");
     43            psFree(psf->growth); psf->growth = NULL;
     44            return false;
     45        }
     46
     47    } else {
     48        bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH");
     49        if (!pmGrowthCurveGenerate (readout, psf, IGNORE_GROWTH, maskVal, markVal)) {
     50            psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections");
     51            psFree(psf->growth); psf->growth = NULL;
     52            return false;
     53        }
    3454    }
    3555
    3656    psLogMsg ("psphot", PS_LOG_MINUTIA, "built growth curve: %f sec\n", psTimerMark ("psphot.growth"));
    3757
     58    float offset = pmGrowthCurveCorrect (psf->growth, PSF_APERTURE);
     59    psLogMsg ("psphot", PS_LOG_DETAIL, "correction from %f to %f: %f mags\n", PSF_APERTURE, REF_RADIUS, offset);
     60
    3861    return true;
    3962}
  • branches/czw_branch/20110406/psphot/src/psphotMergeSources.c

    r31154 r31606  
    137137                pmSource *source = extSourcesTXT->data[i];
    138138                source->mode |= PM_SOURCE_MODE_EXTERNAL;
     139
     140                // the supplied peak flux needs to be re-normalized
     141                source->peak->rawFlux = 1.0;
     142                source->peak->smoothFlux = 1.0;
     143                source->peak->detValue = 1.0;
    139144
    140145                // drop the loaded source modelPSF
  • branches/czw_branch/20110406/psphot/src/psphotModelTest.c

    r29548 r31606  
    226226    // measure the source mags
    227227    pmSourcePhotometryModel (&fitMag, model);
    228     pmSourcePhotometryAper  (&obsMag, NULL, NULL, model, source->pixels, source->variance, source->maskObj, maskVal);
     228    pmSourcePhotometryAper  (NULL, &obsMag, NULL, NULL, model, source->pixels, source->variance, source->maskObj, maskVal);
    229229    fprintf (stderr, "ap: %f, fit: %f, apmifit: %f, nIter: %d\n", obsMag, fitMag, obsMag - fitMag, model->nIter);
    230230
  • branches/czw_branch/20110406/psphot/src/psphotOutput.c

    r31154 r31606  
    7575                 source->peak->xf, source->peak->yf,
    7676                 model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS],
    77                  source->psfMag, source->apMag, source->errMag,
     77                 source->psfMag, source->apMag, source->psfMagErr,
    7878                 model->params->data.F32[PM_PAR_I0],
    7979                 model->params->data.F32[PM_PAR_SXX], model->params->data.F32[PM_PAR_SXY], model->params->data.F32[PM_PAR_SYY],
     
    251251    psMetadataItemSupplement (&status, header, analysis, "NPSFSTAR");
    252252    psMetadataItemSupplement (&status, header, analysis, "APLOSS");
     253    psMetadataItemSupplement (&status, header, analysis, "APREFOFF");
    253254
    254255    psMetadataItemSupplement (&status, header, analysis, "FWHM_MAJ");
  • branches/czw_branch/20110406/psphot/src/psphotPetrosianStats.c

    r31154 r31606  
    163163        if (refRadius->data.F32[i] > apRadius) {
    164164            if (i == 0) {
    165                 psWarning ("does this case make any sense? (refRadius[0] > apRadius)");
     165                psWarning ("does this case make any sense? (refRadius[0] %f > apRadius %f)", refRadius->data.F32[i], apRadius);
    166166                continue;
    167167            } else {
     
    188188        if (!found50 && (fluxSum->data.F32[i] > flux50)) {
    189189            if (i == 0) {
    190                 psWarning ("does this case make any sense? (fluxSum[0] > flux50)");
     190                psWarning ("does this case make any sense? (fluxSum[0] %f > flux50 %f)", fluxSum->data.F32[i], flux50);
    191191                continue;
    192192            } else {
     
    198198        if (!found90 && (fluxSum->data.F32[i] > flux90)) {
    199199            if (i == 0) {
    200                 psWarning ("does this case make any sense? (fluxSum[0] > flux90)");
     200                psWarning ("does this case make any sense? (fluxSum[0] %f > flux90 %f)", fluxSum->data.F32[i], flux90);
    201201                continue;
    202202            } else {
  • branches/czw_branch/20110406/psphot/src/psphotRadialApertures.c

    r31154 r31606  
    9595        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
    9696        if (source->mode & PM_SOURCE_MODE_DEFECT) continue;
    97         if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
     97
     98        // XXX measure radial apertures even for saturated stars
     99        // if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;
    98100
    99101        // limit selection to some SN limit
     
    257259        float SBstdv = sqrt((fluxStd->data.F32[i] / nPix) - PS_SQR(SBmean));
    258260
     261        // XXX report the total flux or the mask-corrected flux?
    259262        // flux->data.F32[i]    = SBmean * Area;
     263        // fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix;
     264
     265        fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]);
    260266        fluxStd->data.F32[i] = SBstdv * Area;
    261         fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix;
    262 
    263         // fill->data.F32[i] /= Area;
     267        fill->data.F32[i] /= Area;
     268
    264269        psTrace ("psphot", 5, "radial bins: %3d  %5.1f : %8.1f +/- %7.2f : %8.1f +/- %8.1f : %4.2f %6.1f\n",
    265270                 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], SBmean, SBstdv, fill->data.F32[i], Area);
  • branches/czw_branch/20110406/psphot/src/psphotRadiusChecks.c

    r29936 r31606  
    184184bool psphotSetRadiusModel (pmModel *model, pmReadout *readout, pmSource *source, psImageMaskType markVal, bool deep) {
    185185
    186     psF32 *PAR = model->params->data.F32;
    187 
    188     pmMoments *moments = source->moments;
    189     if (moments == NULL) return false;
     186    pmPeak *peak = source->peak;
    190187
    191188    // set the fit radius based on the object flux limit and the model
     
    199196
    200197    // redefine the pixels if needed
    201     pmSourceRedefinePixels (source, readout, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius);
    202 
    203     // set the mask to flag the excluded pixels
    204     psImageKeepCircle (source->maskObj, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius, "OR", markVal);
    205     return true;
    206 }
     198    pmSourceRedefinePixels (source, readout, peak->xf, peak->yf, model->fitRadius);
     199
     200    // set the mask to flag the excluded pixels
     201    psImageKeepCircle (source->maskObj, peak->xf, peak->yf, model->fitRadius, "OR", markVal);
     202    return true;
     203}
  • branches/czw_branch/20110406/psphot/src/psphotReadout.c

    r31154 r31606  
    200200    psphotDumpChisqs (config, view, filerule);
    201201
     202    // XXX re-measure the kron mags with models subtracted
     203    psphotKronMasked(config, view, filerule);
     204
    202205    // identify CRs and extended sources (only unmeasured sources are measured)
    203206    psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources)
     
    309312pass1finish:
    310313
     314    // XXX re-measure the kron mags with models subtracted
     315    psphotKronMasked(config, view, filerule);
     316
    311317    // measure source size for the remaining sources
    312318    // NOTE: applies only to NEW (unmeasured) sources
     
    345351      psErrorStackPrint(stderr, "Unable to replace sky");
    346352      psErrorClear();
    347 
    348 /*       psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */
    349 /*       return(psphotReadoutCleanup(config, view, filerule)); */
    350     }
     353    }
     354
    351355    // drop the references to the image pixels held by each source
    352356    if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1
    353357      psErrorStackPrint(stderr, "Unable to free source pixels");
    354358      psErrorClear();
    355 
    356 /*       psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */
    357 /*       return(psphotReadoutCleanup(config, view, filerule)); */
    358     }
     359    }
     360
    359361    // create the exported-metadata and free local data
    360362    return psphotReadoutCleanup(config, view, filerule);
  • branches/czw_branch/20110406/psphot/src/psphotReplaceUnfit.c

    r31154 r31606  
    6767    psAssert (maskVal, "missing mask value?");
    6868
     69    // bit-mask to mark pixels not used in analysis
     70    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     71    assert (markVal);
     72
     73    // maskVal is used to test for rejected pixels, and must include markVal
     74    maskVal |= markVal;
     75
    6976    for (int i = 0; i < sources->n; i++) {
    7077      source = sources->data[i];
  • branches/czw_branch/20110406/psphot/src/psphotRoughClass.c

    r31154 r31606  
    207207        return false;
    208208    }
    209     psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f : DX, DY: %f, %f : nStars %d of %d\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY, psfClump.nStars, psfClump.nTotal);
     209    if (!havePSF) {
     210        psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f : DX, DY: %f, %f : nStars %d of %d\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY, psfClump.nStars, psfClump.nTotal);
     211    } else {
     212        psLogMsg ("psphot", 3, "psf clump  X,  Y: %f, %f : DX, DY: %f, %f : loaded from metadata\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY);
     213    }
    210214
    211215    // get basic parameters, or set defaults
  • branches/czw_branch/20110406/psphot/src/psphotSetThreads.c

    r31154 r31606  
    2525    psFree(task);
    2626
    27     task = psThreadTaskAlloc("PSPHOT_SOURCE_STATS", 10);
     27    task = psThreadTaskAlloc("PSPHOT_SOURCE_STATS", 11);
    2828    task->function = &psphotSourceStats_Threaded;
    2929    psThreadTaskAdd(task);
  • branches/czw_branch/20110406/psphot/src/psphotSourceFits.c

    r31154 r31606  
    146146    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    147147    source->mode |=  PM_SOURCE_MODE_BLEND_FIT;
     148    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    148149    return true;
    149150}
     
    186187
    187188    // build cached model and subtract
     189    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    188190    pmSourceCacheModel (source, maskVal);
    189191    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     
    233235    // XXX save the psf-based moments for output
    234236    psfMoments = *source->moments;
    235     if (!pmSourceMoments (source, radius, 0.0, 0.5, maskVal)) {
     237    if (!pmSourceMoments (source, radius, 0.0, 0.5, 0.0, maskVal)) {
    236238      *source->moments = psfMoments;
    237239      return false;
     
    319321    source->type = PM_SOURCE_TYPE_EXTENDED;
    320322    source->mode |= PM_SOURCE_MODE_EXTMODEL;
     323    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    321324
    322325    // build cached model and subtract
     
    346349    source->modelPSF = psMemIncrRefCounter (DBL->data[0]);
    347350    source->mode     |= PM_SOURCE_MODE_PAIR;
     351    source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
    348352
    349353    // copy most data from the primary source (modelEXT, blends stay NULL)
     
    489493    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
    490494    pmSourceFitModel (source, model, &options, maskVal);
    491     // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
     495    // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
    492496
    493497    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
     
    554558    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
    555559    pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize);
    556     // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
     560    // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);
    557561
    558562    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
  • branches/czw_branch/20110406/psphot/src/psphotSourceSize.c

    r31154 r31606  
    213213
    214214        psVectorAppend (ApOff, dMag);
    215         psVectorAppend (ApErr, source->errMag);
     215        psVectorAppend (ApErr, source->psfMagErr);
    216216    }
    217217    if (num == 0) {
     
    520520        // set nSigmaMAG to include both systematic and poisson error terms.  we include a hard
    521521        // floor on the Ap Sys Err (to be a bit generous).  XXX put the floor in the recipe...
    522         float nSigmaMAG = (dMag - options->ApResid) / hypot(source->errMag, hypot(options->ApSysErr, 0.02));
     522        float nSigmaMAG = (dMag - options->ApResid) / hypot(source->psfMagErr, hypot(options->ApSysErr, 0.02));
    523523        source->extNsigma = nSigmaMAG;
    524524
  • branches/czw_branch/20110406/psphot/src/psphotSourceStats.c

    r31154 r31606  
    9898
    9999    // generate the array of sources, define the associated pixel
     100    bool firstPass = false;
    100101    if (!detections->newSources) {
    101102        detections->newSources = psArrayAllocEmpty (peaks->n);
     103        firstPass = true;
    102104    }
    103105    sources = detections->newSources;
     
    125127        if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {
    126128            fprintf (stderr, "moment failure\n");
     129        }
     130
     131        if (firstPass) {
     132            source->mode2 |= PM_SOURCE_MODE2_PASS1_SRC;
    127133        }
    128134
     
    159165        RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
    160166    }
     167    float MIN_KRON_RADIUS = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_MIN_KRON");
     168    if (!status) {
     169        MIN_KRON_RADIUS = 0.75*SIGMA;
     170    }
    161171
    162172    // threaded measurement of the source magnitudes
     
    186196            PS_ARRAY_ADD_SCALAR(job->args, RADIUS,  PS_TYPE_F32);
    187197            PS_ARRAY_ADD_SCALAR(job->args, SIGMA,   PS_TYPE_F32);
     198            PS_ARRAY_ADD_SCALAR(job->args, MIN_KRON_RADIUS, PS_TYPE_F32);
    188199
    189200            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
     
    215226            } else {
    216227                psScalar *scalar = NULL;
    217                 scalar = job->args->data[7];
     228                scalar = job->args->data[8];
    218229                Nmoments += scalar->data.S32;
    219                 scalar = job->args->data[8];
     230                scalar = job->args->data[9];
    220231                Nfail += scalar->data.S32;
    221                 scalar = job->args->data[9];
     232                scalar = job->args->data[10];
    222233                Nfaint += scalar->data.S32;
    223234            }
     
    231242
    232243    psphotVisualShowMoments (sources);
     244
     245    // clear the mark bits
     246    // psImageMaskPixels (readout->mask, "AND", PS_NOT_IMAGE_MASK(markVal));
    233247
    234248    if (detections->allSources) {
     
    373387    float RADIUS                    = PS_SCALAR_VALUE(job->args->data[3],F32);
    374388    float SIGMA                     = PS_SCALAR_VALUE(job->args->data[4],F32);
    375 
    376     psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA);
    377     psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
     389    float MIN_KRON_RADIUS           = PS_SCALAR_VALUE(job->args->data[5],F32);
     390
     391    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
     392    psImageMaskType markVal         = PS_SCALAR_VALUE(job->args->data[7],PS_TYPE_IMAGE_MASK_DATA);
    378393
    379394    // if no valid pixels, massive swing or very large Mrf, likely saturated source,
     
    431446        if (!(source->peak->type == PM_PEAK_SUSPECT_SATURATION)) {
    432447            // measure basic source moments (no S/N clipping on input pixels)
    433             status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal);
     448            status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, MIN_KRON_RADIUS, maskVal);
    434449        } else {
    435450            // For saturated stars, choose a much larger box NOTE this is slightly sleazy, but
     
    447462
    448463            psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
    449             status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, maskVal);
     464            status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, MIN_KRON_RADIUS, maskVal);
    450465            source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
    451466        }
     
    456471            continue;
    457472        }
     473
     474        // XXX test of masking neighbors when measureing moments (does this fail?)
     475        // psEllipseMoments moments = {source->moments->Mxx, source->moments->Myy, source->moments->Mxy};
     476        // psEllipseAxes axes = psEllipseMomentsToAxes(moments, 20.0);
     477        // psImageMaskCircle (source->maskView, source->peak->x, source->peak->y, 3.0*axes.major, "OR", markVal);
     478
    458479        Nmoments ++;
    459480
     
    492513    float sigma[NSIGMA] = {1.0, 2.0, 3.0, 4.5, 6.0, 9.0, 12.0, 18.0};
    493514    float Sout[NSIGMA];
     515    float Rmin[NSIGMA];
    494516    int   Nout[NSIGMA]; // number of stars found in clump : use this to control the number of regions measured by psphotRoughClass
    495517
     
    513535
    514536            // measure basic source moments (no S/N clipping on input pixels)
    515             status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, maskVal);
     537            status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, 0.0, maskVal);
    516538        }
    517539
     
    524546        pmPSFClump psfClump = pmSourcePSFClump (NULL, NULL, sources, PSF_SN_LIM, PSF_CLUMP_GRID_SCALE, MOMENTS_SX_MAX, MOMENTS_SY_MAX, MOMENTS_AR_MAX);
    525547        psLogMsg ("psphot", 3, "radius %.1f, nStars: %d of %d in clump, nSigma: %5.2f, X,  Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nTotal, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);
     548
     549        Rmin[i] = pmSourceMinKronRadius(sources, PSF_SN_LIM);
    526550
    527551#if 0
     
    549573    // we are looking for sigma for which Sout = 0.65 (or some other value)
    550574    int Nstars = 0;
     575    float minKronRadius = NAN;
    551576    float Sigma = NAN;
    552577    float minS = Sout[0];
     
    565590        Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]);
    566591        Nstars = 0.5*(Nout[i] + Nout[i+1]);
     592        minKronRadius = Rmin[i] + (0.65 - Sout[i])*(Rmin[i+1] - Rmin[i])/(Sout[i+1] - Sout[i]);
    567593    }
    568594    psAssert (isfinite(Sigma), "did we miss a case?");
     
    575601    psMetadataAddF32(analysis, PS_LIST_TAIL, "PSF_MOMENTS_RADIUS", PS_META_REPLACE, "moments limit", 4.0*Sigma);
    576602    psMetadataAddF32(analysis, PS_LIST_TAIL, "PSF_CLUMP_NSTARS", PS_META_REPLACE, "number of stars in clump", Nstars);
    577 
    578     psLogMsg ("psphot", 3, "using window function with sigma = %f\n", Sigma);
     603    psMetadataAddF32(analysis, PS_LIST_TAIL, "MOMENTS_MIN_KRON", PS_META_REPLACE, "minimum Kron Radius", minKronRadius);
     604
     605    psLogMsg ("psphot", 3, "using window function with sigma = %f (Min Kron Radius = %f, Nstars = %d)\n", Sigma, minKronRadius, Nstars);
    579606    return true;
    580607}
  • branches/czw_branch/20110406/psphot/src/psphotVisual.c

    r31154 r31606  
    18671867            continue;
    18681868        }
    1869         if (source->errMag > 0.1) {
     1869        if (source->psfMagErr > 0.1) {
    18701870            xLOW->data.F32[nLOW] = source->moments->Mxx;
    18711871            yLOW->data.F32[nLOW] = source->moments->Myy;
     
    25912591        x->data.F32[n] = source->psfMag;
    25922592        y->data.F32[n] = dMag;
    2593         dy->data.F32[n] = source->errMag;
     2593        dy->data.F32[n] = source->psfMagErr;
    25942594        graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]);
    25952595        graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]);
  • branches/czw_branch/20110406/psphot/test/tap_psphot_stackphot.pro

    r31154 r31606  
    11#!/usr/bin/env mana
    22# -*-sh-*-
     3
     4$KAPA = kapa -noX
    35
    46# config for ppImage to generate chip, mask, weight
  • branches/czw_branch/20110406/pstamp/scripts/detectability_respond.pl

    r31385 r31606  
    718718    foreach my $fpa_id (sort {$query{$a}{ROWNUM}[0] <=> $query{$b}{ROWNUM}[0] } (keys %query)) {
    719719        if ($fpa_id eq 'Not_Set') {
    720             foreach my $index (@{ $query{$a}{ROWNUM} }) {
     720            foreach my $index (@{ $query{$fpa_id}{ROWNUM} }) {
    721721                push @{ $query{$fpa_id}{PROC_ERROR} }, 23;
    722722                push @{ $query{$fpa_id}{NPIX} }, -1;
     
    732732        }
    733733       
    734         print "BADPLACE: $fpa_id\n";
     734        print "BADPLACE: $fpa_id $query{$fpa_id}\n";
     735        foreach my $k (keys %{ $query{$fpa_id} }) {
     736            print "$k $query{$fpa_id}{$k}\n";
     737        }
     738        unless (defined($query{$fpa_id}{ROWNUM})) {
     739            $
    735740        push @{$colData{'ROWNUM'}}, @{ $query{$fpa_id}{ROWNUM} };
    736741        push @{$colData{'ERROR_CODE'}}, @{ $query{$fpa_id}{PROC_ERROR} };
  • branches/czw_branch/20110406/pstamp/scripts/pstamp_job_run.pl

    r30850 r31606  
    146146            # user required uncensored but since stage isn't chip we can't rebuild them
    147147            my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE, 'stop');
    148         } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($params->{state} eq 'update') and ($stage ne 'chip')) {
     148        } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($params->{state} ne 'full') and ($stage ne 'chip')) {
    149149            # we can only restore pixels for chip stage images if the data has been updated.
    150             # XXX: this test is not quite good enough. If all components have been updated then the
    151             # state will be 'full' But this will get us going.
    152             print "Run state is update: will make stamps from destreaked $stage images.\n";
     150            # the data will have been updated if the params->{state} the state when the job was queued is not 'full' (
     151            # XXX: we should probably be looking explicitly at the job and checking for a dep_id
     152            print "Run state was $params->{state}: will make stamps from destreaked $stage images.\n";
    153153            # make stamps from uncensored images
    154154            $muggle = 0;
  • branches/czw_branch/20110406/pstamp/scripts/pstampparse.pl

    r30793 r31606  
    754754    if ( $num_jobs == 0 ) {
    755755        print STDERR "no jobs for row $rownum\n" if $verbose;
    756         insertFakeJobForRow($row, 1, $PSTAMP_NO_JOBS_QUEUED);
     756        insertFakeJobForRow($row, 1, $PSTAMP_NO_IMAGE_MATCH);
    757757        $num_jobs = 1;
     758        $row->{job_num} = 1;
    758759    }
    759760    return $num_jobs;
  • branches/czw_branch/20110406/pswarp/src/pswarpTransformSources.c

    r31159 r31606  
    101101        new->psfMag = source->psfMag;
    102102        new->extMag = source->extMag;
    103         new->errMag = source->errMag;
     103        new->psfMagErr = source->psfMagErr;
    104104        new->apMag = source->apMag;
    105105        new->pixWeightNotBad = source->pixWeightNotBad;
     
    116116          (isfinite(new->psfMag) ? pow(10.0, -0.4*new->psfMag) : NAN);
    117117        new->modelPSF->dparams->data.F32[PM_PAR_I0]=
    118           (isfinite(new->psfMag) ? new->errMag*pow(10.0, -0.4*new->psfMag) : NAN);
     118          (isfinite(new->psfMag) ? new->psfMagErr*pow(10.0, -0.4*new->psfMag) : NAN);
    119119
    120120#if 0
Note: See TracChangeset for help on using the changeset viewer.