IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21536


Ignore:
Timestamp:
Feb 19, 2009, 7:59:50 AM (17 years ago)
Author:
beaumont
Message:

Added visualizations to ppSub. Set up a single variable in pmVisual to control when plots are drawn.

Location:
branches/cnb_branch_20090215
Files:
24 added
10 deleted
202 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branch_20090215/Branches.txt

    r21426 r21536  
     1
     2eam_branch_20090208
     3* Ohana : mucking around with measure.d, average.d, etc to define the
     4  initial PS1 survey DVO output formats.
    15
    26eam_branch_20090203
  • branches/cnb_branch_20090215/Ohana/configure.tcsh

    r19564 r21536  
    1212set memcheck = 0
    1313set use_tcmalloc = 0
     14set use_gnu99 = 0
    1415
    1516set prefix  = ""
     
    7071   set use_tcmalloc = 1
    7172   breaksw;
     73  case --use-gnu99
     74   set use_gnu99 = 1
     75   breaksw;
    7276  case --pedantic
    7377   set pedantic = 1
     
    167171  set CFLAGS = "-g -O0"
    168172endif 
     173
    169174# optimize overrides user-supplied CFLAGS
    170175if ($optimize) set CFLAGS = "-O2"
     
    172177# profiler code
    173178if ($profile) set CFLAGS = "$CFLAGS -pg"
     179
     180# use_gnu99
     181if ($use_gnu99) set CFLAGS = "$CFLAGS -std=gnu99"
    174182
    175183if (! $?CPPFLAGS) then
  • branches/cnb_branch_20090215/Ohana/src/addstar/Makefile

    r20936 r21536  
    2727mkcmf       : $(BIN)/mkcmf.$(ARCH)
    2828
    29 all: addstar addstarc addstard addstart sedstar load2mass skycells
     29all: addstar sedstar load2mass skycells
     30
     31# I need to fix the client/server version of addstar now that I have dropped Stars
     32# as an autocode type and have converted to carrying average and measure
     33# all: addstar addstarc addstard addstart sedstar load2mass skycells
    3034
    3135ADDSTAR = \
     
    4852$(SRC)/find_matches_refstars.$(ARCH).o \
    4953$(SRC)/find_subset.$(ARCH).o \
    50 $(SRC)/get2mass.$(ARCH).o \
    51 $(SRC)/get2mass_as.$(ARCH).o \
    52 $(SRC)/get2mass_as_raw.$(ARCH).o \
    53 $(SRC)/get2mass_dr2.$(ARCH).o \
    54 $(SRC)/get2mass_ops.$(ARCH).o \
    5554$(SRC)/getgsc.$(ARCH).o \
    5655$(SRC)/gettycho.$(ARCH).o \
     
    7170$(SRC)/replace_match.$(ARCH).o \
    7271$(SRC)/resort_catalog.$(ARCH).o \
     72$(SRC)/StarOps.$(ARCH).o \
    7373$(SRC)/ReadStarsFITS.$(ARCH).o \
    7474$(SRC)/ReadStarsTEXT.$(ARCH).o \
     
    106106$(SRC)/find_matches_refstars.$(ARCH).o \
    107107$(SRC)/find_subset.$(ARCH).o \
    108 $(SRC)/get2mass.$(ARCH).o \
    109 $(SRC)/get2mass_as.$(ARCH).o \
    110 $(SRC)/get2mass_as_raw.$(ARCH).o \
    111 $(SRC)/get2mass_dr2.$(ARCH).o \
    112 $(SRC)/get2mass_ops.$(ARCH).o \
    113108$(SRC)/getgsc.$(ARCH).o \
    114109$(SRC)/gettycho.$(ARCH).o \
     
    141136$(SRC)/find_matches_refstars.$(ARCH).o \
    142137$(SRC)/find_subset.$(ARCH).o \
    143 $(SRC)/get2mass.$(ARCH).o \
    144 $(SRC)/get2mass_as.$(ARCH).o \
    145 $(SRC)/get2mass_as_raw.$(ARCH).o \
    146 $(SRC)/get2mass_dr2.$(ARCH).o \
    147 $(SRC)/get2mass_ops.$(ARCH).o \
    148138$(SRC)/getgsc.$(ARCH).o \
    149139$(SRC)/getusno.$(ARCH).o \
     
    209199$(SRC)/replace_match.$(ARCH).o \
    210200$(SRC)/update_coords.$(ARCH).o \
     201$(SRC)/StarOps.$(ARCH).o \
    211202$(SRC)/ConfigInit.$(ARCH).o \
    212203$(SRC)/Shutdown.$(ARCH).o \
     
    252243$(BIN)/mkcmf.$(ARCH)       : $(MKCMF)
    253244
    254 INSTALL = addstar addstarc addstard addstart sedstar load2mass skycells mkcmf
     245INSTALL = addstar sedstar load2mass skycells mkcmf
     246
     247# I need to fix the client/server version of addstar now that I have dropped Stars
     248# as an autocode type and have converted to carrying average and measure
     249# all: addstar addstarc addstard addstart sedstar load2mass skycells
     250# INSTALL = addstar addstarc addstard addstart sedstar load2mass skycells mkcmf
    255251
    256252# dependancy rules for binary code #########################
  • branches/cnb_branch_20090215/Ohana/src/addstar/doc/notes.txt

    r20652 r21536  
     1
     22009.02.11
     3
     4  updating DVO tables with more fields: cleaning up the conversions
     5  from external formats to the DVO internal formats:  I am changing
     6  the APIs to convert directly to the Measure structure, including
     7  conversion functions for the compressed fields (ie, pixels carried
     8  as short).
     9
     10  A few remaining issues:
     11
     12  * t_msec : I've added a field to carry the fractional seconds, but
     13    nothing is yet setting this value, and the query functions do not
     14    use this value.
     15
     16  * various fields are reported in either arcseconds or pixels (eg,
     17    FWHMx, moments, error in centroid).  These are currently not very
     18    consistent, and should be tightened up...
     19
     20    ** if we store these values in pixels, then cameras with a wide
     21       range of plate scales (GPC1 << SkyProbe << AllSky) will all fit
     22       in field with a small dynamic range; since we also provide the
     23       plate scale (as a float), conversions are easy:
     24       GPC1     : 0.26 arcsec / pixel
     25       SkyProbe : 4.5 arcsec / pixel
     26       AllSky   : 3600.0 arcsec / pixel
    127
    2282008.10.11
  • branches/cnb_branch_20090215/Ohana/src/addstar/include/addstar.h

    r21153 r21536  
    2828    fprintf (stderr, "ERROR:  photcode %s not found in photcode table\n", NAME); \
    2929    exit (0); }
     30
     31typedef struct {
     32  char *exthead;
     33  char *extdata;
     34  char *exttype;
     35  int extnum_head;
     36  int extnum_data;
     37} HeaderSet;
     38
     39typedef struct {
     40  Average average;
     41  Measure measure;
     42  int found;
     43} Stars;
    3044
    3145typedef struct {
     
    3953  char *refcat;
    4054} DVO_DATA;
    41 
    42 typedef struct {
    43   char *exthead;
    44   char *extdata;
    45   char *exttype;
    46   int extnum_head;
    47   int extnum_data;
    48 } HeaderSet;
    4955
    5056typedef struct sockaddr_in SockAddress;
     
    9298/* these globals modify the behavior of gstars (KEEP) */
    9399double  SNLIMIT;
     100int     PHOTFLAG_EXCLUDE;
    94101int     ACCEPT_ASTROM;  // accept even bad astrometry solutions (NASTRO == 0)
    95102int     ACCEPT_MOTION;  // accept reference proper motion measurements
     
    137144/*** addstar prototypes ***/
    138145
     146AddstarClientOptions ConfigInit   PROTO((int *argc, char **argv));
     147AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
     148
    139149void       AddToCalibration       PROTO((Average *average, SecFilt *secfilt, Measure *measure, Measure *new, int *next, int Nstar));
    140 AddstarClientOptions ConfigInit   PROTO((int *argc, char **argv));
    141150void       FindCalibration        PROTO((Image *image));
    142151FILE      *GetDB                  PROTO((int *state));
     
    145154void       SetProtect             PROTO((int mode));
    146155int        SetSignals             PROTO((void));
    147 int        Shutdown               PROTO((char *message, ...); )
     156int        Shutdown               PROTO((char *message, ...));
    148157void       TrapSignal             PROTO((int sig));
    149158float      airmass                PROTO((float secz_image, double ra, double dec, double st, double latitude));
     159float      azimuth                PROTO((double ha, double dec, double latitude));
    150160void       SetAirmassQuality      PROTO((int quality));
    151161SkyTable  *SkyTableFromTychoIndex PROTO((char *filename, int VERBOSE));
    152 AddstarClientOptions args         PROTO((int argc, char **argv, AddstarClientOptions options));
    153162void       check_permissions      PROTO((char *basefile));
    154163int        dump_rawstars          PROTO((Stars *stars, int Nstars));
    155164int        edge_check             PROTO((double *x1, double *y1, double *x2, double *y2));
    156165Image     *fakeimage              PROTO((char *rootname, int *Nimage, int photcode));
     166
    157167int        find_matches           PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
    158168int        find_matches_closest   PROTO((SkyRegion *region, Stars *stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
    159169int        find_matches_refstars  PROTO((SkyRegion *region, Stars **stars, int Nstars, Catalog *catalog, AddstarClientOptions options));
     170
    160171Stars    **find_subset            PROTO((SkyRegion *region, Stars *stars, int Nstars, int *NSTARS));
    161172int        gcatalog               PROTO((Catalog *catalog));
    162173Stars     *get2mass               PROTO((SkyRegion *patch, int photcode, int mode, int *NSTARS));
    163174double     get_subpix             PROTO((double x, double y));
     175
     176Stars     *greference             PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
    164177Stars     *getgsc                 PROTO((SkyRegion *patch, int *NSTARS));
    165178Stars     *gettycho               PROTO((SkyRegion *catstats, int photcode, int *Nstars));
    166179Stars     *getusno                PROTO((SkyRegion *catstats, int photcode, int *Nstars));
    167180Stars     *getusnob               PROTO((SkyRegion *catstats, int photcode, int *Nstars));
    168 Image     *gimages                PROTO((FITS_DB *db, Image *image, Coords *mosaic, int *Npimage));
    169 Stars     *grefcat                PROTO((char *Refcat, SkyRegion *catstats, int photcode, int *nstars));
     181
     182// load text-based stars (REF only in the sense of REF photcodes)
    170183Stars     *grefstars              PROTO((char *file, int photcode, int *Nstars));
    171184
     
    249262Stars     *Convert_PS1_DEV_0      PROTO((FTable *table, int *nstars));
    250263Stars     *Convert_PS1_DEV_1      PROTO((FTable *table, int *nstars));
     264Stars     *Convert_PS1_V1         PROTO((FTable *table, int *nstars));
     265
     266int        InitStar               PROTO((Stars *star));
     267short      ShortPixels            PROTO((float pixels));
     268short      ShortDegree            PROTO((float degrees));
    251269
    252270int args_skycells (int argc, char **argv);
  • branches/cnb_branch_20090215/Ohana/src/addstar/include/skycells.h

    r21153 r21536  
    3030  int NX;
    3131  int NY;
    32   int code;
     32  int photcode;
    3333  char name[64];
    3434} SkyRectangle;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/ConfigInit.c

    r20936 r21536  
    3939  ScanConfig (config, "MIN_SN_FSTAT",           "%lf", 0, &SNLIMIT);
    4040  ScanConfig (config, "ADDSTAR_SNLIMIT",        "%lf", 0, &SNLIMIT);
     41
     42  /* exclude stars with bits that match the given photFlags bits */
     43  PHOTFLAG_EXCLUDE = 0;
     44  ScanConfig (config, "ADDSTAR_PHOTFLAG_EXCLUDE", "%d", 0, &PHOTFLAG_EXCLUDE);
    4145
    4246  MAX_CERROR = 0.5; // arcseconds
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/FilterStars.c

    r19823 r21536  
    11# include "addstar.h"
     2# define EXTERNAL_ID FALSE
    23
     4/* exclude some detections based on various filter options:
     5 * *** S/N limit
     6 * *** Acceptable window on detector
     7 * *** bad photFlags
     8 */
     9
     10// the imageID supplied here is the sequence **within this set**
     11// this value is updated based on the image table later
    312Stars *FilterStars (Stars *instars, Image *image, unsigned int imageID) {
    413
     
    1928  ALLOCATE (stars, Stars, image[0].nstar);
    2029  for (N = j = 0; j < image[0].nstar; j++) {
     30
    2131    /* allow for some dynamic filtering of star list */
    22     if (SNLIMIT && instars[j].dM > SNLIMIT) continue;
    23     if (XMAX && (instars[j].X > XMAX)) continue;
    24     if (XMIN && (instars[j].X < XMIN)) continue;
    25     if (YMAX && (instars[j].Y > YMAX)) continue;
    26     if (YMIN && (instars[j].Y < YMIN)) continue;
     32    if (SNLIMIT && instars[j].measure.dM > SNLIMIT) continue;
     33    if (XMAX && (instars[j].measure.Xccd > XMAX)) continue;
     34    if (XMIN && (instars[j].measure.Xccd < XMIN)) continue;
     35    if (YMAX && (instars[j].measure.Yccd > YMAX)) continue;
     36    if (YMIN && (instars[j].measure.Yccd < YMIN)) continue;
     37    if (PHOTFLAG_EXCLUDE && (instars[j].measure.photFlags & PHOTFLAG_EXCLUDE)) continue;
     38
    2739    stars[N] = instars[j];
    2840
    29     XY_to_RD (&stars[N].R, &stars[N].D, stars[N].X, stars[N].Y, &image[0].coords);
    30     stars[N].R = ohana_normalize_angle (stars[N].R);
    31     stars[N].found = -1;
    32     stars[N].code = image[0].photcode;
     41    XY_to_RD (&stars[N].average.R, &stars[N].average.D, stars[N].measure.Xccd, stars[N].measure.Yccd, &image[0].coords);
     42    stars[N].average.R = ohana_normalize_angle (stars[N].average.R);
    3343
    34     RMIN = MIN (RMIN, stars[N].R);
    35     RMAX = MAX (RMAX, stars[N].R);
    36     DMIN = MIN (DMIN, stars[N].D);
    37     DMAX = MAX (DMAX, stars[N].D);
     44    stars[N].measure.photcode = image[0].photcode;
     45
     46    // determine the full coverage of this set of measurements
     47    RMIN = MIN (RMIN, stars[N].average.R);
     48    RMAX = MAX (RMAX, stars[N].average.R);
     49    DMIN = MIN (DMIN, stars[N].average.D);
     50    DMAX = MAX (DMAX, stars[N].average.D);
     51
    3852    /** additional quantities to supply to Stars based on the image data **/
    3953
    40     /* calculate accurate per-star airmass */
    41     stars[N].airmass = airmass (image[0].secz, stars[N].R, stars[N].D, image[0].sidtime, image[0].latitude);
    42     stars[N].Mcal    = image[0].Mcal;
    43     stars[N].t       = image[0].tzero + 1e-4*stars[N].Y*image[0].trate;  /* trate is in 0.1 msec / row */
    44     stars[N].dt      = MTIME;
     54    /* calculate accurate per-star airmass and azimuth */
     55    stars[N].measure.airmass = airmass (image[0].secz, stars[N].average.R, stars[N].average.D, image[0].sidtime, image[0].latitude);
     56    stars[N].measure.az      = azimuth (image[0].sidtime - stars[N].average.R, stars[N].average.D, image[0].latitude);
     57    stars[N].measure.Mcal    = image[0].Mcal;
     58    stars[N].measure.t       = image[0].tzero + 1e-4*stars[N].measure.Yccd*image[0].trate;  /* trate is in 0.1 msec / row */
     59    stars[N].measure.dt      = MTIME;
    4560
    46     if ((stars[N].M > 25.0) && (stars[N].M < 32.0)) {
     61    // watch out for any strange values:
     62    if ((stars[N].measure.M > 25.0) && (stars[N].measure.M < 32.0)) {
    4763      fprintf (stderr, "*");
    4864    }
    49 
    5065    // stars->M is either NAN or a valid inst magnitude
    5166    // stars->dM is either NAN or a valid error
     
    5469    dMx = 0.0;
    5570    if (SUBPIX) {
    56       dMs = get_subpix (stars[N].X, stars[N].Y);
    57       dMx = scat_subpix (stars[N].X, stars[N].Y);
    58       if (!isnan(stars[N].dM)) {
    59         stars[N].dM = hypot (stars[N].dM, dMx);
     71      dMs =  get_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
     72      dMx = scat_subpix (stars[N].measure.Xccd, stars[N].measure.Yccd);
     73      if (!isnan(stars[N].measure.dM)) {
     74        stars[N].measure.dM = hypot (stars[N].measure.dM, dMx);
    6075      }
    6176    }
    6277
    63     if (!isnan(stars[N].M)) {
    64       stars[N].M += MTIME - dMs;
     78    if (!isnan(stars[N].measure.M)) {
     79      stars[N].measure.M  += MTIME - dMs;
    6580    }
    66     if (!isnan(stars[N].Map)) {
    67       stars[N].Map += MTIME - dMs;
     81    if (!isnan(stars[N].measure.Map)) {
     82      stars[N].measure.Map += MTIME - dMs;
    6883    }
    6984   
    70     // XXX currently, this ID is internal only;
    71     // should we use the psphot / other external ID, if available?
    72     stars[N].detID = N; // sequence number within image
    73     stars[N].imageID = imageID; // does this need to be updated?
     85    // the external ID is supplied, but do we trust it?
     86    if (!EXTERNAL_ID) {
     87      stars[N].measure.detID = N; // sequence number within image
     88    }
     89
     90# if (0)
     91    if (PSPS_ID) {
     92      double mjd;
     93      mjd = ohana_sec_to_mjd (image[0].tzero);
     94      // XXX this is clearly wrong : what does PSPS want?
     95      stars[N].measure.extID = PSPS_create_detectid (mjd, imageID);
     96    }
     97# endif
     98
     99    stars[N].measure.imageID = imageID; // this value is update in UpdateImageIDs
    74100
    75101    N ++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/GetFileMode.c

    r20545 r21536  
    77  int Naxis;
    88  int simple, extend, haveNaxis, haveCTYPE;
     9  int tmp, havePHOT_VER, haveTARG_VER;
    910
    1011  gfits_scan (header, "SIMPLE", "%t", 1, &simple);
     
    1415  gfits_scan (header, "EXTEND", "%t", 1, &extend);
    1516   
    16 {
    17     int tmp, havePHOT_VER, haveTARG_VER;
    18 
    19     // SDSS tsObj files have a version number for the PHOTO and
    20     // TS (target selection) pipelines present as header keywords
    21     havePHOT_VER = gfits_scan (header, "PHOT_VER", "%s", 1, &tmp);
    22     haveTARG_VER = gfits_scan (header, "TARG_VER", "%s", 1, &tmp);
    23     if (havePHOT_VER && haveTARG_VER) return SDSS_OBJ;
    24 }
     17  // SDSS tsObj files have a version number for the PHOTO and
     18  // TS (target selection) pipelines present as header keywords
     19  havePHOT_VER = gfits_scan (header, "PHOT_VER", "%s", 1, &tmp);
     20  haveTARG_VER = gfits_scan (header, "TARG_VER", "%s", 1, &tmp);
     21  if (havePHOT_VER && haveTARG_VER) return SDSS_OBJ;
    2522
    2623  if ((Naxis == 2) || TEXTMODE || !simple) {
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/LoadData.c

    r19259 r21536  
    4141    // I need to detect them here and load them with ReadStarsTEXT instead of calling the code
    4242    // below.
     43    // inStars = ReadStarsFITS (f, headers[Nhead], headers[Ndata], &images[0][Nvalid].nstar);
    4344
    4445    // XXX use something to set the chip name? EXTNAME?
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/LoadDataPMM.c

    r19259 r21536  
    8282
    8383    for (i = 0; i < Nline; i++) {
    84       // fscanf (f, "%lf %lf %lf", &ra, &dec, &mag) != EOF) {
    85 
    8684      dparse (&ra,  1, &buffer[i*NBYTE_ASC_TABLE]);
    8785      dparse (&dec, 2, &buffer[i*NBYTE_ASC_TABLE]);
    8886      dparse (&mag, 3, &buffer[i*NBYTE_ASC_TABLE]);
    8987
    90       memset (&inStars[Ninstars], 0, sizeof(Stars));
     88      InitStar (&inStars[Ninstars]);
    9189
    9290      if (ra > 180) {
     
    10098      maxD = MAX(maxD, dec);
    10199
    102       inStars[Ninstars].M       = mag - ZeroPoint + ZeroPt;
    103       inStars[Ninstars].R       = ra;
    104       inStars[Ninstars].D       = dec;
    105       inStars[Ninstars].t       = images[0][0].tzero;
    106       inStars[Ninstars].dt      = images[0][0].exptime;
    107       inStars[Ninstars].code    = code;
    108       inStars[Ninstars].airmass = airmass;
    109       inStars[Ninstars].az      = az;
    110       inStars[Ninstars].found   = -1; // found starts at -1 == not yet found
     100      inStars[Ninstars].average.R        = ra;
     101      inStars[Ninstars].average.D        = dec;
     102
     103      inStars[Ninstars].measure.M        = mag - ZeroPoint + ZeroPt;
     104      inStars[Ninstars].measure.t        = images[0][0].tzero;
     105      inStars[Ninstars].measure.dt       = images[0][0].exptime;
     106      inStars[Ninstars].measure.photcode = code;
     107      inStars[Ninstars].measure.airmass  = airmass;
     108      inStars[Ninstars].measure.az       = az;
     109
    111110      Ninstars++;
    112111      CHECK_REALLOCATE (inStars, Stars, NINSTARS, Ninstars, 10000);
     
    238237    image[0].Mcal = 0.0;
    239238    image[0].Xm   = NAN_S_SHORT;
    240     image[0].code = 0;
     239    image[0].flags = 0;
    241240
    242241    image[0].nstar = 0;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/LoadStars.c

    r16973 r21536  
    6363    }
    6464
     65    // load PMM data if specified (these are not stored as FITS-tables)
    6566    if (PMM_CCD_TABLE != NULL) {
    6667      LoadDataPMM (f, file[i], images, Nimages, &stars, Nstars);
     
    6869    }
    6970
     71    // otherwise, we have FITS-table files: parse their headers to determine the contents
    7072    headers = LoadHeaders (f, &mode, &Nheaders);
    7173    headerSets = MatchHeaders (&extsize, &NheaderSets, mode, headers, Nheaders);
     
    8688    }
    8789
     90    // if these are SDSS data, load with SDSS-specific wrapper
    8891    if (headerSets[0].exttype && !strcmp (headerSets[0].exttype, "SDSS_OBJ")) {
    8992      LoadDataSDSS (f, file[i], images, Nimages, &stars, Nstars, headers, extsize, headerSets, NheaderSets);
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/MatchHeaders.c

    r16810 r21536  
    5151    if (!strcmp (exttype, "PS1_DEV_0")) goto keep;
    5252    if (!strcmp (exttype, "PS1_DEV_1")) goto keep;
     53    if (!strcmp (exttype, "PS1_V1")) goto keep;
    5354    continue;
    5455
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/ReadImageHeader.c

    r20936 r21536  
    200200  image[0].Mcal = 0.0;
    201201  image[0].Xm   = NAN_S_SHORT;
    202   image[0].code = 0;
     202  image[0].flags = 0;
    203203
    204204  /* find expected number of stars */
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/ReadStarsFITS.c

    r17191 r21536  
    4040    stars = Convert_PS1_DEV_1 (&table, &Nstars);
    4141  }
     42  if (!strcmp (type, "PS1_V1")) {
     43    stars = Convert_PS1_V1 (&table, &Nstars);
     44  }
    4245  if (stars == NULL) {
    4346    fprintf (stderr, "ERROR: invalid table type %s\n", type);
     
    6265  ZeroPt = GetZeroPoint();
    6366
    64   /* XXX we need to check at least the size of the loaded table */
    65   // XXX use memset to zero-out the elements before setting
    66 
    67   ALLOCATE (stars, Stars, Nstars);
    68   for (i = 0; i < Nstars; i++) {
    69     stars[i].X      = smpdata[i].X;
    70     stars[i].Y      = smpdata[i].Y;
     67  ALLOCATE (stars, Stars, Nstars);
     68  for (i = 0; i < Nstars; i++) {
     69    InitStar (&stars[i]);
     70
     71    stars[i].measure.Xccd      = smpdata[i].X;
     72    stars[i].measure.Yccd      = smpdata[i].Y;
    7173
    7274    if ((smpdata[i].M >= ZeroPt) || isnan(smpdata[i].M)) {
    73       stars[i].M    = NAN;
    74       stars[i].Map  = NAN;
    75     } else {
    76       stars[i].M    = smpdata[i].M;
    77       stars[i].Map  = smpdata[i].M;
    78     }
    79 
    80     stars[i].dM     = smpdata[i].dM*0.001;
    81     stars[i].dophot = smpdata[i].dophot;
    82 
    83     stars[i].fx     = smpdata[i].fx;
    84     stars[i].fy     = smpdata[i].fy;
    85     stars[i].df     = smpdata[i].df;
     75      stars[i].measure.M       = NAN;
     76      stars[i].measure.Map     = NAN;
     77    } else {
     78      stars[i].measure.M       = smpdata[i].M;
     79      stars[i].measure.Map     = smpdata[i].M;
     80    }
     81
     82    stars[i].measure.dM        = smpdata[i].dM*0.001;
     83
     84    // the dophot type information gets pushed into the upper 2 bytes of photFlags
     85    stars[i].measure.photFlags = (smpdata[i].dophot << 16);
     86
     87    stars[i].measure.FWx       = ShortPixels (smpdata[i].fx);
     88    stars[i].measure.FWy       = ShortPixels (smpdata[i].fy);
     89    stars[i].measure.theta     = ShortDegree (smpdata[i].df);
    8690  }   
    8791  *nstars = Nstars;
     
    101105  ALLOCATE (stars, Stars, Nstars);
    102106  for (i = 0; i < Nstars; i++) {
    103     stars[i].X       = ps1data[i].X;
    104     stars[i].Y       = ps1data[i].Y;
    105     stars[i].dX      = ps1data[i].dX;
    106     stars[i].dY      = ps1data[i].dY;
     107    InitStar (&stars[i]);
     108    stars[i].measure.Xccd     = ps1data[i].X;
     109    stars[i].measure.Yccd     = ps1data[i].Y;
     110
     111    stars[i].measure.dXccd    = ShortPixels(ps1data[i].dX);
     112    stars[i].measure.dYccd    = ShortPixels(ps1data[i].dY);
     113   
    107114    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    108       stars[i].M     = NAN;
    109     } else {
    110       stars[i].M     = ps1data[i].M + ZeroPt;
    111     }
    112     stars[i].dM      = ps1data[i].dM;
    113     stars[i].Mpeak   = ps1data[i].Mpeak;
    114 
    115     stars[i].sky     = ps1data[i].sky;
    116     stars[i].dsky    = ps1data[i].dSky;
    117 
    118     stars[i].fx      = ps1data[i].fx;
    119     stars[i].fy      = ps1data[i].fy;
    120     stars[i].df      = ps1data[i].df;
    121 
    122     stars[i].psfChisq = ps1data[i].psfChisq;
    123     stars[i].psfQual  = ps1data[i].psfQual;
    124 
    125     stars[i].detID   = ps1data[i].detID;
    126 
    127     /* these are set elsewhere */
    128     stars[i].R       = 0.0;
    129     stars[i].D       = 0.0;
    130     stars[i].dR      = 0.0;
    131     stars[i].dD      = 0.0;
    132 
    133     stars[i].uR      = 0.0;
    134     stars[i].uD      = 0.0;
    135     stars[i].duR     = 0.0;
    136     stars[i].duD     = 0.0;
    137 
    138     stars[i].P       = 0.0;
    139     stars[i].dP      = 0.0;
    140 
    141     stars[i].Mcal    = 0;
    142     stars[i].t       = 0;
    143     stars[i].dt      = 0;
    144     stars[i].airmass = 0;
    145     stars[i].code    = 0;
    146     stars[i].found   = 0;
    147 
    148     /* these are not used */
    149     stars[i].Map     = NAN;
    150     stars[i].dophot  = 0;
     115      stars[i].measure.M      = NAN;
     116    } else {
     117      stars[i].measure.M      = ps1data[i].M + ZeroPt;
     118    }
     119    stars[i].measure.Map      = NAN;
     120    stars[i].measure.dM       = ps1data[i].dM;
     121    stars[i].measure.Sky      = ps1data[i].sky;
     122    stars[i].measure.dSky     = ps1data[i].dSky;
     123
     124    stars[i].measure.FWx      = ShortPixels(ps1data[i].fx);
     125    stars[i].measure.FWy      = ShortPixels(ps1data[i].fy);
     126    stars[i].measure.theta    = ShortDegree(ps1data[i].df);
     127
     128    stars[i].measure.psfChisq = ps1data[i].psfChisq;
     129    stars[i].measure.psfQual  = ps1data[i].psfQual;
     130
     131    stars[i].measure.detID    = ps1data[i].detID;
    151132  }   
    152133  *nstars = Nstars;
     
    168149  ALLOCATE (stars, Stars, Nstars);
    169150  for (i = 0; i < Nstars; i++) {
    170     stars[i].X       = ps1data[i].X;
    171     stars[i].Y       = ps1data[i].Y;
    172     stars[i].dX      = ps1data[i].dX;
    173     stars[i].dY      = ps1data[i].dY;
     151    InitStar (&stars[i]);
     152    stars[i].measure.Xccd       = ps1data[i].X;
     153    stars[i].measure.Yccd       = ps1data[i].Y;
     154
     155    stars[i].measure.dXccd      = ShortPixels(ps1data[i].dX);
     156    stars[i].measure.dYccd      = ShortPixels(ps1data[i].dY);
     157
    174158    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
    175         stars[i].M   = NAN;
    176     } else {
    177         stars[i].M   = ps1data[i].M + ZeroPt;
    178     }
    179     stars[i].dM      = ps1data[i].dM;
    180     stars[i].Mpeak   = ps1data[i].Mpeak;
    181 
    182     stars[i].sky     = ps1data[i].sky;
    183     stars[i].dsky    = ps1data[i].dSky;
    184 
    185     stars[i].fx      = ps1data[i].fx;
    186     stars[i].fy      = ps1data[i].fy;
    187     stars[i].df      = ps1data[i].df;
    188 
    189     stars[i].psfChisq  = ps1data[i].psfChisq;
    190     stars[i].psfQual   = ps1data[i].psfQual;
    191     stars[i].crNsigma  = ps1data[i].crNsigma;
    192     stars[i].extNsigma = ps1data[i].extNsigma;
    193 
    194     stars[i].detID     = ps1data[i].detID;
    195     stars[i].flags     = ps1data[i].flags;
    196 
    197     // XXX not defined anyway
    198     // stars[i].stargal   = ps1data[i].stargal;
    199 
    200     /* these are set elsewhere */
    201     stars[i].R       = 0.0;
    202     stars[i].D       = 0.0;
    203     stars[i].dR      = 0.0;
    204     stars[i].dD      = 0.0;
    205 
    206     stars[i].uR      = 0.0;
    207     stars[i].uD      = 0.0;
    208     stars[i].duR     = 0.0;
    209     stars[i].duD     = 0.0;
    210 
    211     stars[i].P       = 0.0;
    212     stars[i].dP      = 0.0;
    213 
    214     stars[i].Mcal    = 0;
    215     stars[i].t       = 0;
    216     stars[i].dt      = 0;
    217     stars[i].airmass = 0;
    218     stars[i].az      = 0;
    219     stars[i].code    = 0;
    220     stars[i].found   = 0;
    221 
    222     /* these are not used */
    223     stars[i].Map     = NAN;
    224     stars[i].dophot  = 0;
    225   }   
    226   *nstars = Nstars;
    227   return (stars);
    228 }
     159        stars[i].measure.M      = NAN;
     160    } else {
     161        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     162    }
     163    stars[i].measure.Map        = NAN;
     164    stars[i].measure.dM         = ps1data[i].dM;
     165    stars[i].measure.Sky        = ps1data[i].sky;
     166    stars[i].measure.dSky       = ps1data[i].dSky;
     167
     168    stars[i].measure.FWx        = ShortPixels(ps1data[i].fx);
     169    stars[i].measure.FWy        = ShortPixels(ps1data[i].fy);
     170    stars[i].measure.theta      = ShortDegree(ps1data[i].df);
     171
     172    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     173    stars[i].measure.psfQual    = ps1data[i].psfQual;
     174    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     175    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     176
     177    stars[i].measure.detID      = ps1data[i].detID;
     178    stars[i].measure.photFlags  = ps1data[i].flags;
     179  }   
     180  *nstars = Nstars;
     181  return (stars);
     182}
     183
     184Stars *Convert_PS1_V1 (FTable *table, int *nstars) {
     185
     186  int i, Nstars;
     187  double ZeroPt;
     188  Stars *stars;
     189  CMF_PS1_V1 *ps1data;
     190
     191  ps1data = gfits_table_get_CMF_PS1_V1 (table, &Nstars, NULL);
     192  ZeroPt = GetZeroPoint();
     193
     194  ALLOCATE (stars, Stars, Nstars);
     195  for (i = 0; i < Nstars; i++) {
     196    InitStar (&stars[i]);
     197    stars[i].measure.Xccd       = ps1data[i].X;
     198    stars[i].measure.Yccd       = ps1data[i].Y;
     199    stars[i].measure.dXccd      = ShortPixels(ps1data[i].dX);
     200    stars[i].measure.dYccd      = ShortPixels(ps1data[i].dY);
     201
     202    stars[i].measure.posangle   = ShortDegree(ps1data[i].posangle);
     203    stars[i].measure.pltscale   = ps1data[i].pltscale;
     204
     205    if ((ps1data[i].M >= 0.0) || isnan(ps1data[i].M)) {
     206        stars[i].measure.M      = NAN;
     207    } else {
     208        stars[i].measure.M      = ps1data[i].M + ZeroPt;
     209    }
     210    stars[i].measure.dM         = ps1data[i].dM;
     211    stars[i].measure.dMcal      = ps1data[i].dMcal;
     212    stars[i].measure.Map        = ps1data[i].Map + ZeroPt;
     213                       
     214    stars[i].measure.Sky        = ps1data[i].sky;
     215    stars[i].measure.dSky       = ps1data[i].dSky;
     216                       
     217    stars[i].measure.psfChisq   = ps1data[i].psfChisq;
     218    stars[i].measure.psfQual    = ps1data[i].psfQual;
     219    stars[i].measure.psfNdof    = ps1data[i].psfNdof;
     220    stars[i].measure.psfNpix    = ps1data[i].psfNpix;
     221    stars[i].measure.crNsigma   = ps1data[i].crNsigma;
     222    stars[i].measure.extNsigma  = ps1data[i].extNsigma;
     223
     224    stars[i].measure.FWx        = ShortPixels(ps1data[i].fx);
     225    stars[i].measure.FWy        = ShortPixels(ps1data[i].fy);
     226    stars[i].measure.theta      = ShortDegree(ps1data[i].df);
     227
     228    stars[i].measure.Mxx        = ShortPixels(ps1data[i].Mxx);
     229    stars[i].measure.Mxy        = ShortPixels(ps1data[i].Mxy);
     230    stars[i].measure.Myy        = ShortPixels(ps1data[i].Myy);
     231                       
     232    stars[i].measure.photFlags  = ps1data[i].flags;
     233
     234    // this is may optionally be replaced by the internal sequence (see FilterStars.c)
     235    stars[i].measure.detID      = ps1data[i].detID;
     236
     237    // the Average fields and the following Measure fields are set in FilterStars after
     238    // the image metadata is in hand:  dR, dD, Mcal, dt, airmass, az, t, imageID, extID,
     239    // averef is set in find_matches, dbFlags is zero on ingest.
     240
     241    // the following fields are currently not being set anywhere: t_msec
     242  }   
     243  *nstars = Nstars;
     244  return (stars);
     245}
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/ReadStarsSDSS.c

    r20688 r21536  
    140140    for (j = 0; j < NFILTER; j++) {
    141141      N = NFILTER*i + j;
    142       stars[N].X         = colc[N];
    143       stars[N].Y         = rowc[N];
    144       stars[N].dX        = colcErr[N];
    145       stars[N].dY        = rowcErr[N];
    146       stars[N].M         = psfCounts[N] + ZeroPt - zeropt[j];
    147       stars[N].dM        = psfCountsErr[N];
    148       stars[N].Map       = fiberCounts[N] + ZeroPt - zeropt[j];
    149       stars[N].Mpeak     = NAN;
    150       stars[N].sky       = sky[N]; // adjust this to counts?
    151       stars[N].dsky      = skyErr[N];
    152       stars[N].fx        = seeing[j]; // reported in arcsec?
    153       stars[N].fy        = seeing[j];
    154       stars[N].df        = 0.0;
    155       stars[N].psfChisq  = prob_psf[N]; // XXX not really the correct value...
    156       stars[N].psfQual   = 0.0;
    157       stars[N].crNsigma  = 0.0;
    158       stars[N].extNsigma = 0.0;
    159       stars[N].detID     = N;
    160       stars[N].R         = ra[i] + dCOS(dec[i]) * offsetRa[N] / 3600.0;
    161       stars[N].D         = dec[i] + offsetDec[N] / 3600.0;
    162       stars[N].dR        = NAN;
    163       stars[N].dD        = NAN;
    164       stars[N].uR        = 0.0; // I don't trust the SDSS proper motions
    165       stars[N].uD        = 0.0; // I don't trust the SDSS proper motions
    166       stars[N].duR       = 0.0;
    167       stars[N].duD       = 0.0;
    168       stars[N].P         = 0.0;
    169       stars[N].dP        = 0.0;
    170       stars[N].Mcal      = 0.0;
    171       stars[N].t         = tzero[j] + clockRate*rowc[N]; // time since row 0
    172       stars[N].dt        = 53.907456; // is this 2048*clockRate ?
     142      InitStar (&stars[N]);
     143     
     144      // any values not explicitly set are left at 0.0
     145      stars[N].average.R         = ra[i] + dCOS(dec[i]) * offsetRa[N] / 3600.0;
     146      stars[N].average.D         = dec[i] + offsetDec[N] / 3600.0;
     147      stars[N].average.dR        = NAN;
     148      stars[N].average.dD        = NAN;
     149
     150      stars[N].measure.Xccd      = colc[N];
     151      stars[N].measure.Yccd      = rowc[N];
     152      stars[N].measure.dXccd     = ShortPixels(colcErr[N]);
     153      stars[N].measure.dYccd     = ShortPixels(rowcErr[N]);
     154      stars[N].measure.M         = psfCounts[N] + ZeroPt - zeropt[j];
     155      stars[N].measure.dM        = psfCountsErr[N];
     156      stars[N].measure.Map       = fiberCounts[N] + ZeroPt - zeropt[j];
     157      stars[N].measure.Sky       = sky[N]; // adjust this to counts?
     158      stars[N].measure.dSky      = skyErr[N];
     159      stars[N].measure.FWx       = ShortPixels(seeing[j]); // reported in arcsec?
     160      stars[N].measure.FWy       = ShortPixels(seeing[j]);
     161      stars[N].measure.psfChisq  = prob_psf[N]; // XXX not really the correct value...
     162      stars[N].measure.detID     = N;
     163      stars[N].measure.t         = tzero[j] + clockRate*rowc[N]; // time since row 0
     164      stars[N].measure.dt        = 53.907456; // is this 2048*clockRate ?
    173165
    174166      SetSDSSFlags (&stars[N], flags[N], flags2[N]);
     
    182174      double Latitude = 32.7803611755; // degrees
    183175
    184       jd = ohana_sec_to_jd (stars[N].t);
     176      jd = ohana_sec_to_jd (stars[N].measure.t);
    185177      sidtime  = 15.0*ohana_lst (jd, Longitude); // sidtime in degrees
    186       altaz (&alt, &az, sidtime - stars[N].R, stars[N].D, Latitude);
    187 
    188       stars[N].airmass   = 1.0 / dCOS(90.0 - alt);
    189       stars[N].az        = az;
    190 
    191       stars[N].code      = photcode[j];
    192       stars[N].found     = -1;
    193       stars[N].dophot    = 0;
     178      altaz (&alt, &az, sidtime - stars[N].average.R, stars[N].average.D, Latitude);
     179
     180      stars[N].measure.airmass   = 1.0 / dCOS(90.0 - alt);
     181      stars[N].measure.az        = az;
     182      stars[N].measure.photcode  = photcode[j];
    194183    }
    195184  }   
     
    202191    strcpy (images[N].coords.ctype, "RA---TAN");
    203192   
    204     images[N].coords.crval1 = stars[0].R;
    205     images[N].coords.crval2 = stars[0].D;
     193    images[N].coords.crval1 = stars[0].average.R;
     194    images[N].coords.crval2 = stars[0].average.D;
    206195   
    207     images[N].coords.crpix1 = stars[0].X;
    208     images[N].coords.crpix2 = stars[0].Y;
     196    images[N].coords.crpix1 = stars[0].measure.Xccd;
     197    images[N].coords.crpix2 = stars[0].measure.Yccd;
    209198    images[N].coords.cdelt1 = images[N].coords.cdelt2 = 0.4 / 3600.0;
    210199
     
    251240
    252241    images[N].trate = clockRate * 1e-4;
    253     images[N].secz = stars[0].airmass;
     242    images[N].secz = stars[0].measure.airmass;
    254243    images[N].ccdnum = camcol;
    255244
     
    257246    images[N].Mcal = 0.0;
    258247    images[N].Xm   = NAN_S_SHORT;
    259     images[N].code = 0;
     248    images[N].flags = 0;
    260249
    261250    images[N].nstar = Nstars;
     
    297286
    298287  // XXX this is wrong, need to roll left to set the correct bit
    299   if (flags1 & 0x00000002) star[0].flags |= 0x0001; // BRIGHT            - 1  1
    300   if (flags1 & 0x00000004) star[0].flags |= 0x0002; // EDGE              - 1  2
    301   if (flags1 & 0x00000008) star[0].flags |= 0x0004; // BLENDED           - 1  3
    302   if (flags1 & 0x00000010) star[0].flags |= 0x0008; // CHILD             - 1  4
    303   if (flags1 & 0x00000020) star[0].flags |= 0x0010; // PEAKCENTER        - 1  5
    304   if (flags1 & 0x00000040) star[0].flags |= 0x0020; // NODEBLEND         - 1  6
    305   if (flags1 & 0x00040000) star[0].flags |= 0x0040; // SATUR             - 1 18
    306   if (flags1 & 0x00080000) star[0].flags |= 0x0080; // NOTCHECKED        - 1 19
    307   if (flags1 & 0x10000000) star[0].flags |= 0x0100; // BINNED1           - 1 28
    308   if (flags1 & 0x20000000) star[0].flags |= 0x0200; // BINNED2           - 1 29
    309   if (flags1 & 0x40000000) star[0].flags |= 0x0400; // BINNED4           - 1 30
    310   if (flags2 & 0x00000040) star[0].flags |= 0x0800; // LOCAL_EDGE        - 2  7
    311   if (flags2 & 0x00000800) star[0].flags |= 0x1000; // INTERP_CENTER     - 2 12
    312   if (flags2 & 0x00002000) star[0].flags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
    313   if (flags2 & 0x02000000) star[0].flags |= 0x4000; // NOTCHECKED_CENTER - 2 26
     288  if (flags1 & 0x00000002) star[0].measure.photFlags |= 0x0001; // BRIGHT            - 1  1
     289  if (flags1 & 0x00000004) star[0].measure.photFlags |= 0x0002; // EDGE              - 1  2
     290  if (flags1 & 0x00000008) star[0].measure.photFlags |= 0x0004; // BLENDED           - 1  3
     291  if (flags1 & 0x00000010) star[0].measure.photFlags |= 0x0008; // CHILD             - 1  4
     292  if (flags1 & 0x00000020) star[0].measure.photFlags |= 0x0010; // PEAKCENTER        - 1  5
     293  if (flags1 & 0x00000040) star[0].measure.photFlags |= 0x0020; // NODEBLEND         - 1  6
     294  if (flags1 & 0x00040000) star[0].measure.photFlags |= 0x0040; // SATUR             - 1 18
     295  if (flags1 & 0x00080000) star[0].measure.photFlags |= 0x0080; // NOTCHECKED        - 1 19
     296  if (flags1 & 0x10000000) star[0].measure.photFlags |= 0x0100; // BINNED1           - 1 28
     297  if (flags1 & 0x20000000) star[0].measure.photFlags |= 0x0200; // BINNED2           - 1 29
     298  if (flags1 & 0x40000000) star[0].measure.photFlags |= 0x0400; // BINNED4           - 1 30
     299  if (flags2 & 0x00000040) star[0].measure.photFlags |= 0x0800; // LOCAL_EDGE        - 2  7
     300  if (flags2 & 0x00000800) star[0].measure.photFlags |= 0x1000; // INTERP_CENTER     - 2 12
     301  if (flags2 & 0x00002000) star[0].measure.photFlags |= 0x2000; // DEBLEND_NOPEAK    - 2 14
     302  if (flags2 & 0x02000000) star[0].measure.photFlags |= 0x4000; // NOTCHECKED_CENTER - 2 26
    314303  return (TRUE);
    315304
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/ReadStarsTEXT.c

    r16810 r21536  
    77
    88  int j, N, Nextra, Ninstar, Nskip, Nbytes, nbytes;
    9   int done;
     9  int done, itmp;
    1010  char *buffer, *c, *c2;
    11   double tmp;
     11  double tmp, fx, fy, df;
    1212  double ZeroPt;
    1313  Stars *stars;
     
    6666    Nextra = nbytes % BYTES_STAR;
    6767    for (j = 0; (j < Ninstar) && (N < *nstars); j++, N++) {
    68       dparse (&stars[N].X,  1, &buffer[j*BYTES_STAR]);
    69       dparse (&stars[N].Y,  2, &buffer[j*BYTES_STAR]);
    70       dparse (&stars[N].M,  3, &buffer[j*BYTES_STAR]);
    71       if ((stars[N].M > ZeroPt) || isnan(stars[N].M)) {
    72         stars[N].M = NAN;
     68      InitStar (&stars[N]);
     69      fparse (&stars[N].measure.Xccd,  1, &buffer[j*BYTES_STAR]);
     70      fparse (&stars[N].measure.Yccd,  2, &buffer[j*BYTES_STAR]);
     71      fparse (&stars[N].measure.M,  3, &buffer[j*BYTES_STAR]);
     72      if ((stars[N].measure.M > ZeroPt) || isnan(stars[N].measure.M)) {
     73        stars[N].measure.M = NAN;
    7374      }
    7475
    7576      /* cmp files carry dM in millimags */
    7677      dparse (&tmp, 4, &buffer[j*BYTES_STAR]);
    77       stars[N].dM = 0.001*tmp;
     78      stars[N].measure.dM = 0.001*tmp;
    7879
     80      // the dophot type information get pushed into the upper 2 bytes of photFlags
    7981      dparse (&tmp,         5, &buffer[j*BYTES_STAR]);
    80       stars[N].dophot = tmp;
     82      itmp = tmp;
     83      stars[N].measure.photFlags = (itmp << 16);
    8184
    8285      // XXX I've removed the Mgal field from the measure.d table, and am using Map
     
    8790
    8891      // dparse (&stars[N].Mgal, 7, &buffer[j*BYTES_STAR]);
    89       dparse (&stars[N].Map,  8, &buffer[j*BYTES_STAR]);
    90       dparse (&stars[N].fx,   9, &buffer[j*BYTES_STAR]);
    91       dparse (&stars[N].fy,  10, &buffer[j*BYTES_STAR]);
    92       dparse (&stars[N].df,  11, &buffer[j*BYTES_STAR]);
     92      fparse (&stars[N].measure.Map,  8, &buffer[j*BYTES_STAR]);
     93      dparse (&fx,   9, &buffer[j*BYTES_STAR]);
     94      dparse (&fy,  10, &buffer[j*BYTES_STAR]);
     95      dparse (&df,  11, &buffer[j*BYTES_STAR]);
     96
     97      stars[N].measure.FWx   = ShortPixels (fx);
     98      stars[N].measure.FWy   = ShortPixels (fy);
     99      stars[N].measure.theta = ShortDegree (df);
    93100    }
    94101  }
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/SEDfit.c

    r16810 r21536  
    164164    outcat[0].average[Nave].measureOffset = Nmeas;
    165165    outcat[0].average[Nave].missingOffset = -1;
    166     outcat[0].average[Nave].code          = 0;
     166    outcat[0].average[Nave].flags         = 0;
    167167
    168168    for (j = 0; j < Nsec; j++) {
     
    181181    for (j = 0; valid && (j < Nmodel); j++) {
    182182      n = modelRow[j];
    183       outcat[0].measure[Nmeas].dR       = 0.0;
    184       outcat[0].measure[Nmeas].dD       = 0.0;
    185       outcat[0].measure[Nmeas].M        = table[0].row[minFit.row][0].mags[n] + minFit.Md;
    186       outcat[0].measure[Nmeas].dM       = 0.0;
    187       outcat[0].measure[Nmeas].Mcal     = 0;
    188       outcat[0].measure[Nmeas].t        = TIMEREF;
    189       outcat[0].measure[Nmeas].averef   = Nave;
    190       outcat[0].measure[Nmeas].photcode = table[0].code[n];
    191       outcat[0].measure[Nmeas].dophot  = 0;
    192       outcat[0].measure[Nmeas].dbFlags  = 0;
    193       outcat[0].measure[Nmeas].dt       = 0xffff;
    194 
    195       outcat[0].measure[Nmeas].airmass  = 0;
    196       outcat[0].measure[Nmeas].FWx      = NAN_S_SHORT;
    197       outcat[0].measure[Nmeas].FWy      = NAN_S_SHORT;
    198       outcat[0].measure[Nmeas].theta    = NAN_S_SHORT;
     183      outcat[0].measure[Nmeas].dR        = 0.0;
     184      outcat[0].measure[Nmeas].dD        = 0.0;
     185      outcat[0].measure[Nmeas].M         = table[0].row[minFit.row][0].mags[n] + minFit.Md;
     186      outcat[0].measure[Nmeas].dM        = 0.0;
     187      outcat[0].measure[Nmeas].Mcal      = 0;
     188      outcat[0].measure[Nmeas].t         = TIMEREF;
     189      outcat[0].measure[Nmeas].averef    = Nave;
     190      outcat[0].measure[Nmeas].photcode  = table[0].code[n];
     191      outcat[0].measure[Nmeas].photFlags = 0;
     192      outcat[0].measure[Nmeas].dbFlags   = 0;
     193      outcat[0].measure[Nmeas].dt        = 0xffff;
     194                                         
     195      outcat[0].measure[Nmeas].airmass   = 0;
     196      outcat[0].measure[Nmeas].FWx       = NAN_S_SHORT;
     197      outcat[0].measure[Nmeas].FWy       = NAN_S_SHORT;
     198      outcat[0].measure[Nmeas].theta     = NAN_S_SHORT;
    199199
    200200      outcat[0].average[Nave].Nmeasure++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/SkyListForStars.c

    r16040 r21536  
    11# include "addstar.h"
     2
     3void sort_stars_ra (Stars *stars, int N) {
     4
     5# define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
     6# define COMPARE(A,B)(stars[A].average.R < stars[B].average.R)
     7
     8  OHANA_SORT (N, COMPARE, SWAPFUNC);
     9
     10# undef SWAPFUNC
     11# undef COMPARE
     12
     13}
    214
    315SkyList *SkyListForStars (SkyTable *table, int depth, Stars *stars, int Nstars) {
     
    1729  sort_stars_ra (stars, Nstars); /* sort by RA */
    1830  for (i = 0; i < Nstars; i++) {
    19     if (stars[i].found) continue;
    20     here = SkyRegionByPoint (table, depth, stars[i].R, stars[i].D);
    21     stars[i].found = TRUE;
     31    if (stars[i].found == -2) continue;
     32    here = SkyRegionByPoint (table, depth, stars[i].average.R, stars[i].average.D);
     33    stars[i].found = -2;
    2234    /* search forward for all contained stars */
    2335    for (j = i; j < Nstars; j++) {
    24       if (stars[j].R >= here[0].regions[0][0].Rmax) break;
    25       if (stars[j].R <  here[0].regions[0][0].Rmin) break;
    26       if (stars[j].D <  here[0].regions[0][0].Dmin) continue;
    27       if (stars[j].D >= here[0].regions[0][0].Dmax) continue;
    28       stars[j].found = TRUE;
     36      if (stars[j].average.R >= here[0].regions[0][0].Rmax) break;
     37      if (stars[j].average.R <  here[0].regions[0][0].Rmin) break;
     38      if (stars[j].average.D <  here[0].regions[0][0].Dmin) continue;
     39      if (stars[j].average.D >= here[0].regions[0][0].Dmax) continue;
     40      stars[j].found = -2;
    2941    }
    3042    list[0].regions[Nr] = here[0].regions[0];
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/UpdateImageIDs.c

    r20182 r21536  
    4343
    4444  for (i = 0; i < Nstars; i++) {
    45     stars[i].imageID += imageID;
     45    stars[i].measure.imageID += imageID;
    4646  }
    4747
    4848  imageID += Nimages;
    4949  status = gfits_modify (&db.header, "IMAGEID", "%u", 1, imageID);
    50  
    5150
    5251  if (isEmpty) {
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/addstar.c

    r18721 r21536  
    135135        break;
    136136      case M_REFCAT:
    137         stars = grefcat (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
     137        stars = greference (argv[1], skylist[0].regions[i], options.photcode, &Nstars);
    138138      case M_REFLIST:
    139139        subset = find_subset (skylist[0].regions[i], stars, Nstars, &Nsubset);
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/airmass.c

    r8642 r21536  
    11# include "addstar.h"
    22
    3 static int AirmassQuality = FALSE;
     3static int AirmassQuality = TRUE;
    44
    55void SetAirmassQuality (int quality) {
     
    2525  return (secz);
    2626}
     27
     28// ha/dec -> az
     29float azimuth (double ha, double dec, double latitude) {
     30
     31  double rdec, rlat, rha;
     32  double sinh, cosh;
     33  float az;
     34
     35  rdec = RAD_DEG*dec;
     36  rha = RAD_DEG*ha;
     37  rlat = RAD_DEG*latitude;
     38
     39  sinh = - cos (rdec) * sin (rha);
     40  cosh =   sin (rdec) * cos (rlat) - cos (rdec) * cos (rha) * sin (rlat);
     41
     42  az = DEG_RAD * atan2 (sinh, cosh);
     43
     44  return az;
     45}
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/args.c

    r20183 r21536  
    2828    remove_argument (N, &argc, argv);
    2929  }
     30  if ((N = get_argument (argc, argv, "-resort"))) {
     31    options.mode = M_RESORT;
     32    remove_argument (N, &argc, argv);
     33  }
    3034  if ((N = get_argument (argc, argv, "-fakeimage"))) {
    3135    options.mode = M_FAKEIMAGE;
     
    3640    remove_argument (N, &argc, argv);
    3741    FAKE_THETA = atof (argv[N]);
    38     remove_argument (N, &argc, argv);
    39   }
    40   if ((N = get_argument (argc, argv, "-resort"))) {
    41     options.mode = M_RESORT;
    4242    remove_argument (N, &argc, argv);
    4343  }
     
    221221  /*** optional situations ***/
    222222  /* choose high quality airmass vs low quality airmass (per-star vs per-image) */
    223   QUALITY_AIRMASS = FALSE;
     223  QUALITY_AIRMASS = TRUE;
    224224  if ((N = get_argument (argc, argv, "-quality-airmass"))) {
    225225    remove_argument (N, &argc, argv);
    226226    QUALITY_AIRMASS = TRUE;
     227  }
     228  if ((N = get_argument (argc, argv, "-quick-airmass"))) {
     229    remove_argument (N, &argc, argv);
     230    QUALITY_AIRMASS = FALSE;
    227231  }
    228232  /* choose high quality airmass vs low quality airmass (per-star vs per-image) */
     
    310314
    311315  fprintf (stderr, "USAGE: addstar (filename)\n");
     316  fprintf (stderr, "USAGE: addstar -list (filename)\n");
    312317  fprintf (stderr, "USAGE: addstar -cat (catalog)\n");
    313318  fprintf (stderr, "USAGE: addstar -ref (filename)\n");
    314319  fprintf (stderr, "USAGE: addstar -fakeimage (ra) (dec) (theta) (name)\n");
    315320  fprintf (stderr, "USAGE: addstar -resort (SkyRegion)\n");
     321  fprintf (stderr, "USAGE: addstar -ppm (filename)\n");
    316322  exit (2);
    317323}
     
    322328  fprintf (stderr, "  addstar (filename)\n");
    323329  fprintf (stderr, "     add specified image (cmp format) to database\n\n");
     330  fprintf (stderr, "  addstar -list (filename)\n");
     331  fprintf (stderr, "     add list of images (cmp format) to database\n\n");
    324332  fprintf (stderr, "  addstar -ref (filename)");
    325333  fprintf (stderr, "     add ASCII data (ra dec mag dmag) to database\n\n");
     
    328336  fprintf (stderr, "  addstar -resort (SkyRegion)");
    329337  fprintf (stderr, "     perform measure sorting for the specified catalog\n\n");
     338  fprintf (stderr, "  addstar -fakeimage (ra) (dec) (theta) (name)");
     339  fprintf (stderr, "     insert a fake image in the db\n\n");
     340  fprintf (stderr, "  addstar -pmm (filename)");
     341  fprintf (stderr, "     insert pmm table into database\n\n");
    330342
    331343  fprintf (stderr, "  optional flags:\n");
     
    340352  fprintf (stderr, "  -missed                     : skipped 'missed' entries\n");
    341353  fprintf (stderr, "  -replace                    : replace time/photcode measurements (no duplication)\n");
    342   fprintf (stderr, "  -closest                    : use closest-star algorith\n");
     354  fprintf (stderr, "  -closest                    : use closest-star algorith (default)\n");
     355  fprintf (stderr, "  -all-matches                : use all-matches algorith\n");
    343356  fprintf (stderr, "  -nosort                     : don't re-sort the measure entries (improves speed)\n");
    344357  fprintf (stderr, "  -update                     : only update the new rows (forces -nosort)\n");
     358  fprintf (stderr, "  -force-sort                 : \n");
    345359  fprintf (stderr, "  -image                      : only insert image data\n");
    346360  fprintf (stderr, "  -cal                        : perform zero-point calibration\n");
     361  fprintf (stderr, "  -excal                      : apply supplied zero-point calibration\n");
     362  fprintf (stderr, "  -incal                      : perform zero-point calibration\n");
     363  fprintf (stderr, "  -quality-airmass            : use per-star airmass values (default)\n");
     364  fprintf (stderr, "  -quick-airmass              : use per-image airmass values\n");
     365  fprintf (stderr, "  -subpix                     : apply subpixel corrections\n");
    347366  fprintf (stderr, "  -skyprobe                   : specify skyprobe mode\n");
     367  fprintf (stderr, "  -2massquality               : define 2MASS quality flags to keep\n");
    348368  fprintf (stderr, "  -accept                     : accept bad astrometry from header\n");
    349369  fprintf (stderr, "  -accept-astrom              : accept bad astrometry from header\n");
    350370  fprintf (stderr, "  -accept-motion              : accept proper-motion data from reference\n");
     371  fprintf (stderr, "  -accept-time                : use TZERO supplied in header\n");
     372  fprintf (stderr, "  -no-stars                   : skip the stars\n");
    351373  fprintf (stderr, "  -force                      : force read of database with inconsistent info\n");
     374  fprintf (stderr, "  -textmode                   : force textmode for file (ignore header clues)\n");
    352375  fprintf (stderr, "  -v                          : verbose mode\n");
    353376  fprintf (stderr, "  -dump (mode)                : output test data. Currently supported values for mode are: 'rawdata', 'cal'.\n");
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/dump.c

    r3404 r21536  
    1111    fprintf (f, "%4d  %10.6f %10.6f  %8.2f %8.2f  %7.2f %7.2f\n",
    1212             i,
    13              stars[i].R, stars[i].D,
    14              stars[i].X, stars[i].Y,
    15              stars[i].M, stars[i].dM);
     13             stars[i].average.R, stars[i].average.D,
     14             stars[i].measure.Xccd, stars[i].measure.Yccd,
     15             stars[i].measure.M, stars[i].measure.dM);
    1616  }
    1717
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/fakeimage.c

    r16983 r21536  
    129129    image[i+1].ccdnum = 0xff;
    130130
    131     image[i+1].Mcal = 0.0;
    132     image[i+1].Xm   = NAN_S_SHORT;
    133     image[i+1].code = 0;
     131    image[i+1].Mcal  = 0.0;
     132    image[i+1].Xm    = NAN_S_SHORT;
     133    image[i+1].flags = 0;
    134134
    135135    image[i+1].nstar = 0;
     
    189189  image[0].Mcal = 0.0;
    190190  image[0].Xm   = NAN_S_SHORT;
    191   image[0].code = 0;
     191  image[0].flags = 0;
    192192  image[0].nstar = 0;
    193193  image[0].Myyyy = 0;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/find_matches.c

    r20936 r21536  
    6262  strcpy (tcoords.ctype, "RA---ARC");
    6363
    64   /* build spatial index (RA sort) */
     64  /* build spatial index (RA sort) referencing input array sequence */
    6565  Nstars = 0;
    6666  for (i = 0; i < NstarsIn; i++) {
    67     status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     67    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].average.R, stars[i].average.D, &tcoords);
    6868    if (!status) continue;
    6969    N1[Nstars] = i;
     
    104104  /** find matched stars **/
    105105  for (i = j = 0; (i < Nstars) && (j < Nave); ) {
    106         if (!finite(X1[i]) || !finite(Y1[i])) {
     106    if (!finite(X1[i]) || !finite(Y1[i])) {
    107107      i++;
    108108      continue;
     
    147147
    148148      /** add measurements for this star **/
    149       /** dR,dD now represent arcsec **/
    150       catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].R);
     149
     150      // set the new measurements
     151      catalog[0].measure[Nmeas]          = stars[N].measure;
     152
     153      // the following measure elements cannot be set until here:
     154      catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
     155      catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].average.D);
     156      catalog[0].measure[Nmeas].dbFlags  = 0;
     157      catalog[0].measure[Nmeas].averef   = n; // this must be an absolute sequence number, if partial average is loaded
     158      catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
     159      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
     160
     161      // rationalize dR:
    151162      if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
    152163          // average on high end of boundary, move star up
    153           stars[N].R += 360.0;
    154           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
     164          stars[N].average.R += 360.0;
     165          catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    155166      }
    156167      if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
    157168          // average on low end of boundary, move star down
    158           stars[N].R -= 360.0;
    159           catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
     169          stars[N].average.R -= 360.0;
     170          catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    160171      }
    161172      if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
    162173          fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    163174                   catalog[0].average[n].R, catalog[0].average[n].D,
    164                    stars[N].R, stars[N].D,
     175                   stars[N].average.R, stars[N].average.D,
    165176                   X1[i], X2[J],
    166177                   Y1[i], Y2[J]);
    167178      }
    168       catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].D);
    169 
    170       catalog[0].measure[Nmeas].Xccd     = stars[N].X;
    171       catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
    172 
    173       catalog[0].measure[Nmeas].M        = stars[N].M;
    174       catalog[0].measure[Nmeas].dM       = stars[N].dM;  /* error in input files stored in thousandths of mag */
    175       catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
    176       catalog[0].measure[Nmeas].t        = stars[N].t;
    177       catalog[0].measure[Nmeas].averef   = n;              /* this must be an absolute sequence number, if partial average is loaded */
    178       catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
    179       catalog[0].measure[Nmeas].dophot   = stars[N].dophot; 
    180       catalog[0].measure[Nmeas].dbFlags  = 0;
    181       catalog[0].measure[Nmeas].dt       = stars[N].dt;
    182       catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
    183 
    184       catalog[0].measure[Nmeas].photFlags = stars[N].flags;
    185       catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
    186       catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
    187       catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
    188       catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
    189       catalog[0].measure[Nmeas].Sky       = stars[N].sky;
    190       catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
    191 
    192       catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
    193 
    194       catalog[0].measure[Nmeas].detID     = stars[N].detID;
    195       catalog[0].measure[Nmeas].imageID   = stars[N].imageID;
    196 
    197       catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
    198       catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
    199 
    200       catalog[0].measure[Nmeas].Map      = stars[N].Map;
    201       catalog[0].measure[Nmeas].FWx      = 100*stars[N].fx;
    202       catalog[0].measure[Nmeas].FWy      = 100*stars[N].fy;
    203       catalog[0].measure[Nmeas].theta    = (0xffff/360.0)*stars[N].df;
    204        
     179
    205180      /* adds the measurement to the calibration if appropriate color terms are found */
    206181      /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
     
    266241    N = N1[i];
    267242    if (stars[N].found >= 0) continue;
    268     if (!IN_REGION (stars[N].R, stars[N].D)) continue;
    269 
    270     catalog[0].average[Nave].R             = stars[N].R;
    271     catalog[0].average[Nave].D             = stars[N].D;
    272     catalog[0].average[Nave].Xp            = 0;
     243    if (!IN_REGION (stars[N].average.R, stars[N].average.D)) continue;
     244
     245    catalog[0].average[Nave].R             = stars[N].average.R;
     246    catalog[0].average[Nave].D             = stars[N].average.D;
     247    catalog[0].average[Nave].dR            = 0;
     248    catalog[0].average[Nave].dD            = 0;
     249
    273250    catalog[0].average[Nave].Nmeasure      = 1;
    274251    catalog[0].average[Nave].Nmissing      = 0;
     252    catalog[0].average[Nave].Nextend       = 0;
     253
    275254    catalog[0].average[Nave].measureOffset = Nmeas;
    276255    catalog[0].average[Nave].missingOffset = -1;
    277     catalog[0].average[Nave].code          = 0;
    278 
    279     catalog[0].average[Nave].dR        = 0;
    280     catalog[0].average[Nave].dD        = 0;
    281     catalog[0].average[Nave].uR        = 0;
    282     catalog[0].average[Nave].uD        = 0;
    283     catalog[0].average[Nave].duR       = 0;
    284     catalog[0].average[Nave].duD       = 0;
    285     catalog[0].average[Nave].P         = 0;
    286     catalog[0].average[Nave].dP        = 0;
    287 
    288     catalog[0].average[Nave].objID     = objID;
    289     catalog[0].average[Nave].catID     = catID;
     256    catalog[0].average[Nave].extendOffset  = -1;
     257
     258    catalog[0].average[Nave].uR            = 0;
     259    catalog[0].average[Nave].uD            = 0;
     260    catalog[0].average[Nave].duR           = 0;
     261    catalog[0].average[Nave].duD           = 0;
     262    catalog[0].average[Nave].P             = 0;
     263    catalog[0].average[Nave].dP            = 0;
     264
     265    catalog[0].average[Nave].Xp            = 0;
     266    catalog[0].average[Nave].ChiSq         = 0.0;
     267    catalog[0].average[Nave].Npos          = 0;
     268
     269    catalog[0].average[Nave].objID         = objID;
     270    catalog[0].average[Nave].catID         = catID;
     271    catalog[0].average[Nave].flags         = 0;
     272
    290273    objID ++;
    291274
    292275    for (j = 0; j < Nsecfilt; j++) {
    293       catalog[0].secfilt[Nave*Nsecfilt+j].M  = NAN;
    294       catalog[0].secfilt[Nave*Nsecfilt+j].dM = NAN;
    295       catalog[0].secfilt[Nave*Nsecfilt+j].Xm = NAN_S_SHORT;
    296     }
    297 
    298     catalog[0].measure[Nmeas].Xccd     = stars[N].X;
    299     catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
    300 
     276      catalog[0].secfilt[Nave*Nsecfilt+j].M     = NAN;
     277      catalog[0].secfilt[Nave*Nsecfilt+j].dM    = NAN;
     278      catalog[0].secfilt[Nave*Nsecfilt+j].Xm    = NAN_S_SHORT;
     279      catalog[0].secfilt[Nave*Nsecfilt+j].M_20  = NAN_S_SHORT;
     280      catalog[0].secfilt[Nave*Nsecfilt+j].M_80  = NAN_S_SHORT;
     281      catalog[0].secfilt[Nave*Nsecfilt+j].Ncode = 0;
     282      catalog[0].secfilt[Nave*Nsecfilt+j].Nused = 0;
     283    }
     284
     285    // supply the measurments from this detection
     286    catalog[0].measure[Nmeas]           = stars[N].measure;
     287
     288    // the following measure elements cannot be set until here:
    301289    catalog[0].measure[Nmeas].dR        = 0.0;
    302290    catalog[0].measure[Nmeas].dD        = 0.0;
    303     catalog[0].measure[Nmeas].M         = stars[N].M;
    304     catalog[0].measure[Nmeas].dM        = stars[N].dM;
    305     catalog[0].measure[Nmeas].Mcal      = stars[N].Mcal;
    306     catalog[0].measure[Nmeas].t         = stars[N].t;
    307     catalog[0].measure[Nmeas].averef    = Nave;           /* XXX EAM : must be absolute Nave if partial read */
    308     catalog[0].measure[Nmeas].photcode  = stars[N].code;  /* photcode */
    309     catalog[0].measure[Nmeas].dophot    = stars[N].dophot; 
    310291    catalog[0].measure[Nmeas].dbFlags   = 0;
    311     catalog[0].measure[Nmeas].dt        = stars[N].dt;
    312     catalog[0].measure[Nmeas].airmass   = stars[N].airmass;
    313 
    314     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
    315     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
    316     catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
    317     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
    318     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
    319     catalog[0].measure[Nmeas].Sky       = stars[N].sky;
    320     catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
    321 
    322     catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
    323 
    324     catalog[0].measure[Nmeas].detID     = stars[N].detID;
    325     catalog[0].measure[Nmeas].imageID   = stars[N].imageID;
    326 
    327     catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
    328     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
    329 
    330     catalog[0].measure[Nmeas].Map       = stars[N].Map;
    331     catalog[0].measure[Nmeas].FWx       = 100*stars[N].fx;
    332     catalog[0].measure[Nmeas].FWy       = 100*stars[N].fy;
    333     catalog[0].measure[Nmeas].theta     = (0xffff/360.0)*stars[N].df;
    334     /* XXX replace df here with theta, right? */
     292    catalog[0].measure[Nmeas].averef    = Nave; // XXX EAM : must be absolute Nave if partial read
     293    catalog[0].measure[Nmeas].objID     = catalog[0].average[Nave].objID;
     294    catalog[0].measure[Nmeas].catID     = catalog[0].catID;
    335295
    336296    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/find_matches_closest.c

    r20936 r21536  
    77  double *X1, *Y1, *X2, *Y2;
    88  double dX, dY, dR;
    9   int *N1, *N2,  *next_meas, *next_miss;
    10   int Nave, NAVE, Nmeas, NMEAS, Nmiss, NMISS, Nmatch;
     9  int *N1, *N2,  *next_meas;
     10  int Nave, NAVE, Nmeas, NMEAS, Nmatch;
    1111  int Nsecfilt, Nsec;
    1212  unsigned int objID, catID;
     
    3737  Nmatch = 0;
    3838  NMEAS = Nmeas = catalog[0].Nmeasure;
    39   NMISS = Nmiss = catalog[0].Nmissing;
    4039
    4140  // current max obj ID for this catalog
     
    6665  Nstars = 0;
    6766  for (i = 0; i < NstarsIn; i++) {
    68     status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].R, stars[i].D, &tcoords);
     67    status = RD_to_XY (&X1[Nstars], &Y1[Nstars], stars[i].average.R, stars[i].average.D, &tcoords);
    6968    if (!status) continue;
    7069    N1[Nstars] = i;
     
    9291  if (Nave > 1) sort_coords_index (X2, Y2, N2, Nave);
    9392
    94   /* set up pointers for linked list of measure, missing */
     93  /* set up pointers for linked list of measure */
    9594  if (catalog[0].sorted && (catalog[0].Nmeasure == catalog[0].Nmeas_disk)) {
    9695    // this version is only valid if we have done a full catalog load, and if the catalog
     
    10099    next_meas = build_measure_links (catalog[0].average, Nave, catalog[0].measure, Nmeas);
    101100  }   
    102   next_miss = init_missing_links (catalog[0].average, Nave, catalog[0].missing, Nmiss);
    103   /* missing MUST be written 'sorted', or not at all */
    104101
    105102  /* choose a radius for matches */
     
    167164       
    168165    /** add measurements for this star **/
     166
     167    // set the new measurements
     168    catalog[0].measure[Nmeas]          = stars[N].measure;
     169
    169170    /** dR,dD now represent arcsec **/
    170     catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].R);
     171    catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
     172    catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].average.D);
     173    catalog[0].measure[Nmeas].dbFlags  = 0;
     174    catalog[0].measure[Nmeas].averef   = n;
     175    catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
     176    catalog[0].measure[Nmeas].catID    = catalog[0].catID;
     177
     178    // rationalize dR
    171179    if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
    172180      // average on high end of boundary, move star up
    173       stars[N].R += 360.0;
    174       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
     181      stars[N].average.R += 360.0;
     182      catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    175183    }
    176184    if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
    177185      // average on low end of boundary, move star down
    178       stars[N].R -= 360.0;
    179       catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].R);
     186      stars[N].average.R -= 360.0;
     187      catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N].average.R);
    180188    }
    181189    if (fabs(catalog[0].measure[Nmeas].dR) > 10*RADIUS) {
    182190      fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    183191               catalog[0].average[n].R, catalog[0].average[n].D,
    184                stars[N].R, stars[N].D,
     192               stars[N].average.R, stars[N].average.D,
    185193               X1[i], X2[Jmin],
    186194               Y1[i], Y2[Jmin]);
    187195    }
    188     catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N].D);
    189 
    190     /* XXX need to add dX, dY : need to load into stars[N].dX,dY */
    191     /* XXX need to add stargal, Sky, dSky, qPSF, detID, imageID */
    192     catalog[0].measure[Nmeas].Xccd     = stars[N].X;
    193     catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
    194 
    195     catalog[0].measure[Nmeas].M        = stars[N].M;
    196     catalog[0].measure[Nmeas].dM       = stars[N].dM;  /* error in input files stored in thousandths of mag */
    197     catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
    198     catalog[0].measure[Nmeas].t        = stars[N].t;
    199     catalog[0].measure[Nmeas].averef   = n;
    200     catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
    201     catalog[0].measure[Nmeas].dophot   = stars[N].dophot; 
    202     catalog[0].measure[Nmeas].dbFlags  = 0;
    203     catalog[0].measure[Nmeas].dt       = stars[N].dt;
    204     catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
    205 
    206     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
    207     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
    208     catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
    209     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
    210     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
    211     catalog[0].measure[Nmeas].Sky       = stars[N].sky;
    212     catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
    213 
    214     catalog[0].measure[Nmeas].stargal   = 0;
    215 
    216     catalog[0].measure[Nmeas].detID     = stars[N].detID;
    217     catalog[0].measure[Nmeas].imageID   = stars[N].imageID;
    218 
    219     catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
    220     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
    221 
    222     catalog[0].measure[Nmeas].Map       = stars[N].Map;
    223 
    224     // XXX saturate range for FWx, FWy, theta
    225     // XXX convert to unsigned int for these...
    226     catalog[0].measure[Nmeas].FWx      = 100*stars[N].fx;
    227     catalog[0].measure[Nmeas].FWy      = 100*stars[N].fy;
    228     catalog[0].measure[Nmeas].theta    = (0xffff/360.0)*stars[N].df;
    229        
     196
     197
     198    /* adds the measurement to the calibration if appropriate color terms are found */
     199    /* we call this before (optionally) setting the average magnitude to avoid auto-correlations */
     200    if (options.calibrate) {
     201      AddToCalibration (&catalog[0].average[n], &catalog[0].secfilt[n*Nsecfilt], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
     202    }
     203
    230204    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
    231205    /* in UPDATE mode, this value is not saved; use relphot to recalculate */
     
    234208        catalog[0].secfilt[n*Nsecfilt+Nsec].M = PhotCat (&catalog[0].measure[Nmeas]);
    235209      }
    236     }
    237 
    238     /* adds the measurement to the calibration if appropriate color terms are found */
    239     if (options.calibrate) {
    240       AddToCalibration (&catalog[0].average[n], &catalog[0].secfilt[n*Nsecfilt], catalog[0].measure, &catalog[0].measure[Nmeas], next_meas, N);
    241210    }
    242211
     
    270239    N = N1[i];
    271240    if (stars[N].found >= 0) continue;
    272     if (!IN_REGION (stars[N].R, stars[N].D)) continue;
    273 
    274     catalog[0].average[Nave].R             = stars[N].R;
    275     catalog[0].average[Nave].D             = stars[N].D;
    276     catalog[0].average[Nave].Xp            = 0;
     241    if (!IN_REGION (stars[N].average.R, stars[N].average.D)) continue;
     242
     243    catalog[0].average[Nave].R             = stars[N].average.R;
     244    catalog[0].average[Nave].D             = stars[N].average.D;
     245    catalog[0].average[Nave].dR            = 0;
     246    catalog[0].average[Nave].dD            = 0;
     247
    277248    catalog[0].average[Nave].Nmeasure      = 1;
    278249    catalog[0].average[Nave].Nmissing      = 0;
     250    catalog[0].average[Nave].Nextend       = 0;
     251
    279252    catalog[0].average[Nave].measureOffset = Nmeas;
    280253    catalog[0].average[Nave].missingOffset = -1;
    281     catalog[0].average[Nave].code          = 0;
    282 
    283     catalog[0].average[Nave].dR        = 0;
    284     catalog[0].average[Nave].dD        = 0;
    285     catalog[0].average[Nave].uR        = 0;
    286     catalog[0].average[Nave].uD        = 0;
    287     catalog[0].average[Nave].duR       = 0;
    288     catalog[0].average[Nave].duD       = 0;
    289     catalog[0].average[Nave].P         = 0;
    290     catalog[0].average[Nave].dP        = 0;
    291 
    292     catalog[0].average[Nave].objID     = objID;
    293     catalog[0].average[Nave].catID     = catID;
     254    catalog[0].average[Nave].extendOffset  = -1;
     255
     256    catalog[0].average[Nave].uR            = 0;
     257    catalog[0].average[Nave].uD            = 0;
     258    catalog[0].average[Nave].duR           = 0;
     259    catalog[0].average[Nave].duD           = 0;
     260    catalog[0].average[Nave].P             = 0;
     261    catalog[0].average[Nave].dP            = 0;
     262
     263    catalog[0].average[Nave].Xp            = 0;
     264    catalog[0].average[Nave].ChiSq         = 0.0;
     265    catalog[0].average[Nave].Npos          = 0;
     266
     267    catalog[0].average[Nave].objID         = objID;
     268    catalog[0].average[Nave].catID         = catID;
     269    catalog[0].average[Nave].flags         = 0;
     270
    294271    objID ++;
    295272
     
    298275      catalog[0].secfilt[Nave*Nsecfilt+j].dM = NAN;
    299276      catalog[0].secfilt[Nave*Nsecfilt+j].Xm = NAN_S_SHORT;
    300     }
    301 
    302     catalog[0].measure[Nmeas].Xccd     = stars[N].X;
    303     catalog[0].measure[Nmeas].Yccd     = stars[N].Y;
    304 
     277      catalog[0].secfilt[Nave*Nsecfilt+j].M_20  = NAN_S_SHORT;
     278      catalog[0].secfilt[Nave*Nsecfilt+j].M_80  = NAN_S_SHORT;
     279      catalog[0].secfilt[Nave*Nsecfilt+j].Ncode = 0;
     280      catalog[0].secfilt[Nave*Nsecfilt+j].Nused = 0;
     281    }
     282
     283    // supply the measurments from this detection
     284    catalog[0].measure[Nmeas]           = stars[N].measure;
     285
     286    // the following measure elements cannot be set until here:
    305287    catalog[0].measure[Nmeas].dR       = 0.0;
    306288    catalog[0].measure[Nmeas].dD       = 0.0;
    307     catalog[0].measure[Nmeas].M        = stars[N].M;
    308     catalog[0].measure[Nmeas].dM       = stars[N].dM;
    309     catalog[0].measure[Nmeas].Mcal     = stars[N].Mcal;
    310     catalog[0].measure[Nmeas].t        = stars[N].t;
     289    catalog[0].measure[Nmeas].dbFlags  = 0;
    311290    catalog[0].measure[Nmeas].averef   = Nave;
    312     catalog[0].measure[Nmeas].photcode = stars[N].code;  /* photcode */
    313     catalog[0].measure[Nmeas].dophot   = stars[N].dophot; 
    314     catalog[0].measure[Nmeas].dbFlags  = 0;
    315     catalog[0].measure[Nmeas].dt       = stars[N].dt;
    316     catalog[0].measure[Nmeas].airmass  = stars[N].airmass;
    317 
    318     catalog[0].measure[Nmeas].photFlags = stars[N].flags;
    319     catalog[0].measure[Nmeas].qPSF      = stars[N].psfQual;
    320     catalog[0].measure[Nmeas].psfChisq  = stars[N].psfChisq;
    321     catalog[0].measure[Nmeas].crNsigma  = stars[N].crNsigma;
    322     catalog[0].measure[Nmeas].extNsigma = stars[N].extNsigma;
    323     catalog[0].measure[Nmeas].Sky       = stars[N].sky;
    324     catalog[0].measure[Nmeas].dSky      = stars[N].dsky;
    325 
    326     catalog[0].measure[Nmeas].stargal   = 0;
    327 
    328     catalog[0].measure[Nmeas].detID     = stars[N].detID;
    329     catalog[0].measure[Nmeas].imageID   = stars[N].imageID;
    330 
    331     catalog[0].measure[Nmeas].dXccd     = stars[N].dX;
    332     catalog[0].measure[Nmeas].dYccd     = stars[N].dY;
    333 
    334     catalog[0].measure[Nmeas].Map      = stars[N].Map;
    335     catalog[0].measure[Nmeas].FWx      = 100*stars[N].fx;
    336     catalog[0].measure[Nmeas].FWy      = 100*stars[N].fy;
    337     catalog[0].measure[Nmeas].theta    = (0xffff/360.0)*stars[N].df;
     291    catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
     292    catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    338293
    339294    /* set the average magnitude if not already set and the photcode.equiv is not 0 */
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/find_matches_refstars.c

    r18374 r21536  
    6969 
    7070  for (i = 0; i < Nstars; i++) {
    71     RD_to_XY (&X1[i], &Y1[i], stars[i][0].R, stars[i][0].D, &tcoords);
     71    RD_to_XY (&X1[i], &Y1[i], stars[i][0].average.R, stars[i][0].average.D, &tcoords);
    7272    N1[i] = i;
    7373  }
     
    134134      /* find last measurement of this star */
    135135      for (k = 0; k < catalog[0].average[n].Nmeasure - 1; k++) m = next[m];
     136
    136137      /* set up references */
    137138      next[Nmeas] = next[m];
    138139      next[m] = Nmeas;
     140
    139141      /* last just was moved */
    140142      if (next[Nmeas] == -1) last = Nmeas;
    141143       
    142144      /** add measurements for this star **/
     145
     146      // set the new measurements
     147      catalog[0].measure[Nmeas]          = stars[N][0].measure;
     148
    143149      /** *** dR,dD now in arcsec *** **/
    144       catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].R);
    145       catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].D);
    146       catalog[0].measure[Nmeas].M        = stars[N][0].M;
    147       catalog[0].measure[Nmeas].dM       = stars[N][0].dM;
    148       catalog[0].measure[Nmeas].Mcal     = 0;
    149       catalog[0].measure[Nmeas].t        = (TIMEREF == 0) ? stars[N][0].t : TIMEREF; /** careful : time_t vs e_time **/
     150      catalog[0].measure[Nmeas].dR       = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
     151      catalog[0].measure[Nmeas].dD       = 3600.0*(catalog[0].average[n].D - stars[N][0].average.D);
     152
     153      // rationalize dR:
     154      if (catalog[0].measure[Nmeas].dR > +180.0*3600.0) {
     155          // average on high end of boundary, move star up
     156          stars[N][0].average.R += 360.0;
     157          catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
     158      }
     159      if (catalog[0].measure[Nmeas].dR < -180.0*3600.0) {
     160          // average on low end of boundary, move star down
     161          stars[N][0].average.R -= 360.0;
     162          catalog[0].measure[Nmeas].dR = 3600.0*(catalog[0].average[n].R - stars[N][0].average.R);
     163      }
     164
    150165      catalog[0].measure[Nmeas].averef   = n;
    151       catalog[0].measure[Nmeas].photcode = stars[N][0].code;
    152       catalog[0].measure[Nmeas].dophot   = 0;
    153166      catalog[0].measure[Nmeas].dbFlags  = 0;
    154       catalog[0].measure[Nmeas].dt       = 0xffff;
    155 
    156       catalog[0].measure[Nmeas].Map      = NAN;
    157       catalog[0].measure[Nmeas].airmass  = 0;
    158       catalog[0].measure[Nmeas].FWx      = stars[N][0].fx; // XXX make sure these are zero'ed as needed
    159       catalog[0].measure[Nmeas].FWy      = stars[N][0].fy; // XXX make sure these are zero'ed as needed
    160       catalog[0].measure[Nmeas].theta    = stars[N][0].df; // XXX make sure these are zero'ed as needed
    161        
    162       catalog[0].measure[Nmeas].photFlags = stars[N][0].flags; // XXX make sure these are zero'ed as needed
    163       catalog[0].measure[Nmeas].qPSF      = 0;
    164       catalog[0].measure[Nmeas].psfChisq  = 0;
    165       catalog[0].measure[Nmeas].crNsigma  = 0;
    166       catalog[0].measure[Nmeas].extNsigma = 0;
    167       catalog[0].measure[Nmeas].Sky       = 0;
    168       catalog[0].measure[Nmeas].dSky      = 0;
    169 
    170       catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
    171 
    172       catalog[0].measure[Nmeas].detID     = 0;
    173       catalog[0].measure[Nmeas].imageID   = 0;
    174 
    175       catalog[0].measure[Nmeas].dXccd     = 0;
    176       catalog[0].measure[Nmeas].dYccd     = 0;
    177 
    178       catalog[0].measure[Nmeas].Xccd     = stars[N][0].X; // XXX make sure these are zero'ed as needed
    179       catalog[0].measure[Nmeas].Yccd     = stars[N][0].Y; // XXX make sure these are zero'ed as needed
     167      catalog[0].measure[Nmeas].objID    = catalog[0].average[n].objID;
     168      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
     169
     170      catalog[0].measure[Nmeas].t        = (TIMEREF == 0) ? stars[N][0].measure.t      : TIMEREF; /** careful : time_t vs e_time **/
     171      catalog[0].measure[Nmeas].t_msec   = (TIMEREF == 0) ? stars[N][0].measure.t_msec : TIMEREF; /** careful : time_t vs e_time **/
    180172
    181173      if (ACCEPT_MOTION) {
    182         catalog[0].average[n].uR         = stars[N][0].uR;
    183         catalog[0].average[n].uD         = stars[N][0].uD;
    184         catalog[0].average[n].duR        = stars[N][0].duR;
    185         catalog[0].average[n].duD        = stars[N][0].duD;
    186         catalog[0].average[n].P          = stars[N][0].P;
    187         catalog[0].average[n].dP         = stars[N][0].dP;
     174        catalog[0].average[n].uR         = stars[N][0].average.uR;
     175        catalog[0].average[n].uD         = stars[N][0].average.uD;
     176        catalog[0].average[n].duR        = stars[N][0].average.duR;
     177        catalog[0].average[n].duD        = stars[N][0].average.duD;
     178        catalog[0].average[n].P          = stars[N][0].average.P;
     179        catalog[0].average[n].dP         = stars[N][0].average.dP;
    188180      }
    189181
     
    233225  for (i = 0; (i < Nstars) && !options.only_match; i+=NREFSTAR_GROUP) {
    234226    N = N1[i];
    235     if (stars[N][0].found >= 0) continue;
    236 
    237     catalog[0].average[Nave].R             = stars[N][0].R;
    238     catalog[0].average[Nave].D             = stars[N][0].D;
    239     catalog[0].average[Nave].Xp            = 0;
     227    if (stars[N][0].found > -1) continue;
     228
     229    catalog[0].average[Nave].R             = stars[N][0].average.R;
     230    catalog[0].average[Nave].D             = stars[N][0].average.D;
     231
    240232    catalog[0].average[Nave].Nmeasure      = NREFSTAR_GROUP;
    241233    catalog[0].average[Nave].Nmissing      = 0;
     234    catalog[0].average[Nave].Nextend       = 0;
     235
    242236    catalog[0].average[Nave].measureOffset = Nmeas;
    243237    catalog[0].average[Nave].missingOffset = -1;
    244     catalog[0].average[Nave].code          = 0;
     238    catalog[0].average[Nave].extendOffset  = -1;
    245239
    246240    if (ACCEPT_MOTION) {
    247       catalog[0].average[Nave].dR    = stars[N][0].dR;
    248       catalog[0].average[Nave].dD    = stars[N][0].dD;
    249       catalog[0].average[Nave].uR    = stars[N][0].uR;
    250       catalog[0].average[Nave].uD    = stars[N][0].uD;
    251       catalog[0].average[Nave].duR   = stars[N][0].duR;
    252       catalog[0].average[Nave].duD   = stars[N][0].duD;
    253       catalog[0].average[Nave].P     = stars[N][0].P;
    254       catalog[0].average[Nave].dP    = stars[N][0].dP;
     241      catalog[0].average[Nave].dR          = stars[N][0].average.dR;
     242      catalog[0].average[Nave].dD          = stars[N][0].average.dD;
     243      catalog[0].average[Nave].uR          = stars[N][0].average.uR;
     244      catalog[0].average[Nave].uD          = stars[N][0].average.uD;
     245      catalog[0].average[Nave].duR         = stars[N][0].average.duR;
     246      catalog[0].average[Nave].duD         = stars[N][0].average.duD;
     247      catalog[0].average[Nave].P           = stars[N][0].average.P;
     248      catalog[0].average[Nave].dP          = stars[N][0].average.dP;
    255249    } else {
    256       catalog[0].average[Nave].dR    = 0;
    257       catalog[0].average[Nave].dD    = 0;
    258       catalog[0].average[Nave].uR    = 0;
    259       catalog[0].average[Nave].uD    = 0;
    260       catalog[0].average[Nave].duR   = 0;
    261       catalog[0].average[Nave].duD   = 0;
    262       catalog[0].average[Nave].P     = 0;
    263       catalog[0].average[Nave].dP    = 0;
    264     }
    265 
    266     catalog[0].average[Nave].objID     = objID;
    267     catalog[0].average[Nave].catID     = catID;
     250      catalog[0].average[Nave].dR          = 0;
     251      catalog[0].average[Nave].dD          = 0;
     252      catalog[0].average[Nave].uR          = 0;
     253      catalog[0].average[Nave].uD          = 0;
     254      catalog[0].average[Nave].duR         = 0;
     255      catalog[0].average[Nave].duD         = 0;
     256      catalog[0].average[Nave].P           = 0;
     257      catalog[0].average[Nave].dP          = 0;
     258      catalog[0].average[Nave].Xp          = 0;
     259    }
     260
     261    catalog[0].average[Nave].Xp            = 0;
     262    catalog[0].average[Nave].ChiSq         = 0.0;
     263    catalog[0].average[Nave].Npos          = 0;
     264
     265    catalog[0].average[Nave].objID         = objID;
     266    catalog[0].average[Nave].catID         = catID;
     267    catalog[0].average[Nave].flags         = 0;
     268
    268269    objID ++;
    269270
    270271    for (j = 0; j < Nsecfilt; j++) {
    271       catalog[0].secfilt[Nave*Nsecfilt+j].M  = NAN;
    272       catalog[0].secfilt[Nave*Nsecfilt+j].dM = NAN;
    273       catalog[0].secfilt[Nave*Nsecfilt+j].Xm = NAN_S_SHORT;
     272      catalog[0].secfilt[Nave*Nsecfilt+j].M     = NAN;
     273      catalog[0].secfilt[Nave*Nsecfilt+j].dM    = NAN;
     274      catalog[0].secfilt[Nave*Nsecfilt+j].Xm    = NAN_S_SHORT;
     275      catalog[0].secfilt[Nave*Nsecfilt+j].M_20  = NAN_S_SHORT;
     276      catalog[0].secfilt[Nave*Nsecfilt+j].M_80  = NAN_S_SHORT;
     277      catalog[0].secfilt[Nave*Nsecfilt+j].Ncode = 0;
     278      catalog[0].secfilt[Nave*Nsecfilt+j].Nused = 0;
    274279    }
    275280
    276281    for (j = 0; j < NREFSTAR_GROUP; j++) {
    277282      N = N1[i + j];
     283
     284      catalog[0].measure[Nmeas]          = stars[N][0].measure;
     285
    278286      catalog[0].measure[Nmeas].dR       = 0.0;
    279287      catalog[0].measure[Nmeas].dD       = 0.0;
    280       catalog[0].measure[Nmeas].M        = stars[N][0].M;
    281       catalog[0].measure[Nmeas].dM       = stars[N][0].dM;
    282       catalog[0].measure[Nmeas].Mcal     = 0;
    283       catalog[0].measure[Nmeas].t        = (stars[N][0].t == 0) ? TIMEREF : stars[N][0].t; /** careful : time_t vs e_time **/
     288
     289      catalog[0].measure[Nmeas].t        = (stars[N][0].measure.t == 0) ? TIMEREF : stars[N][0].measure.t;      /** careful : time_t vs e_time **/
     290      catalog[0].measure[Nmeas].t_msec   = (stars[N][0].measure.t == 0) ?       0 : stars[N][0].measure.t_msec; /** careful : time_t vs e_time **/
     291      catalog[0].measure[Nmeas].dbFlags  = 0;
    284292      catalog[0].measure[Nmeas].averef   = Nave;
    285       catalog[0].measure[Nmeas].photcode = stars[N][0].code;
    286       catalog[0].measure[Nmeas].dophot   = 0;
    287       catalog[0].measure[Nmeas].dbFlags  = 0;
    288       catalog[0].measure[Nmeas].dt       = 0xffff;
    289 
    290       catalog[0].measure[Nmeas].photFlags = stars[N][0].flags; // XXX make sure these are zero'ed as needed
    291       catalog[0].measure[Nmeas].qPSF      = 0;
    292       catalog[0].measure[Nmeas].psfChisq  = 0;
    293       catalog[0].measure[Nmeas].crNsigma  = 0;
    294       catalog[0].measure[Nmeas].extNsigma = 0;
    295       catalog[0].measure[Nmeas].Sky       = 0;
    296       catalog[0].measure[Nmeas].dSky      = 0;
    297 
    298       catalog[0].measure[Nmeas].stargal   = 0; // XXX not yet set
    299 
    300       catalog[0].measure[Nmeas].detID     = 0;
    301       catalog[0].measure[Nmeas].imageID   = 0;
    302 
    303       catalog[0].measure[Nmeas].dXccd     = 0;
    304       catalog[0].measure[Nmeas].dYccd     = 0;
    305 
    306       catalog[0].measure[Nmeas].Xccd     = stars[N][0].X; // XXX make sure these are zero'ed as needed
    307       catalog[0].measure[Nmeas].Yccd     = stars[N][0].Y; // XXX make sure these are zero'ed as needed
    308 
    309       catalog[0].measure[Nmeas].airmass  = 0;
    310       catalog[0].measure[Nmeas].Map      = NAN;
    311       catalog[0].measure[Nmeas].FWx      = stars[N][0].fx; // XXX make sure these are zero'ed as needed
    312       catalog[0].measure[Nmeas].FWy      = stars[N][0].fy; // XXX make sure these are zero'ed as needed
    313       catalog[0].measure[Nmeas].theta    = stars[N][0].df; // XXX make sure these are zero'ed as needed
    314 
    315       catalog[0].measure[Nmeas].Xccd     = 0.0;
    316       catalog[0].measure[Nmeas].Yccd     = 0.0;
     293      catalog[0].measure[Nmeas].objID    = catalog[0].average[Nave].objID;
     294      catalog[0].measure[Nmeas].catID    = catalog[0].catID;
    317295
    318296      stars[N][0].found = Nmeas;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/find_subset.c

    r5443 r21536  
    2020  /* find stars within ra,dec region */
    2121  for (i = N = 0; i < Nstars; i++) {
    22     if (stars[i].R <  RA0)  continue;
    23     if (stars[i].R >= RA1)  continue;
    24     if (stars[i].D <  DEC0) continue;
    25     if (stars[i].D >= DEC1) continue;
     22    if (stars[i].average.R <  RA0)  continue;
     23    if (stars[i].average.R >= RA1)  continue;
     24    if (stars[i].average.D <  DEC0) continue;
     25    if (stars[i].average.D >= DEC1) continue;
    2626
    2727    subset[N] = &stars[i];
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/get2mass_dr2.c

    r16810 r21536  
    6868        dparse (&J,  1, &buffer[NBYTE*i + 53]);
    6969        dparse (&dJ, 2, &buffer[NBYTE*i + 53]);
    70         stars[Nstars].M    = J;
    71         stars[Nstars].dM   = dJ;
    72         stars[Nstars].code = TM_J;
     70        stars[Nstars].M        = J;
     71        stars[Nstars].dM       = dJ;
     72        stars[Nstars].photcode = TM_J;
    7373      }
    7474      if (photcode == TM_H) {
    7575        dparse (&H,  1, &buffer[NBYTE*i + 72]);
    7676        dparse (&dH, 2, &buffer[NBYTE*i + 72]);
    77         stars[Nstars].M    = H;
    78         stars[Nstars].dM   = dH;
    79         stars[Nstars].code = TM_H;
     77        stars[Nstars].M        = H;
     78        stars[Nstars].dM       = dH;
     79        stars[Nstars].photcode = TM_H;
    8080      }
    8181      if (photcode == TM_K) {
    8282        dparse (&K,  1, &buffer[NBYTE*i + 91]);
    8383        dparse (&dK, 2, &buffer[NBYTE*i + 91]);
    84         stars[Nstars].M    = K;
    85         stars[Nstars].dM   = dK;
    86         stars[Nstars].code = TM_K;
     84        stars[Nstars].M        = K;
     85        stars[Nstars].dM       = dK;
     86        stars[Nstars].photcode = TM_K;
    8787      }
    8888      Nstars ++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/get2mass_full.c

    r17439 r21536  
    1515  ptr = next2MASSfield (ptr); // dec (assumed to be already set)
    1616  ptr = next2MASSfield (ptr); // err_maj
    17   star[0][0].fx = strtod (ptr, NULL);
     17  star[0][0].measure.FWx = ShortPixels(strtod (ptr, NULL));
    1818  ptr = next2MASSfield (ptr); // err_min
    19   star[0][0].fy = strtod (ptr, NULL);
     19  star[0][0].measure.FWy = ShortPixels(strtod (ptr, NULL));
    2020  ptr = next2MASSfield (ptr); // err_ang
    21   star[0][0].df = strtod (ptr, NULL);
    22 
    23   star[2][0].fx = star[2][0].fx = star[0][0].fx;
    24   star[2][0].fy = star[2][0].fy = star[0][0].fy;
    25   star[2][0].df = star[2][0].df = star[0][0].df;
     21  star[0][0].measure.theta = ShortPixels(strtod (ptr, NULL));
     22
     23  star[2][0].measure.FWx   = star[2][0].measure.FWx   = star[0][0].measure.FWx;
     24  star[2][0].measure.FWy   = star[2][0].measure.FWy   = star[0][0].measure.FWy;
     25  star[2][0].measure.theta = star[2][0].measure.theta = star[0][0].measure.theta;
    2626
    2727  ptr = next2MASSfield (ptr); // designation (skip)
    2828
    2929  ptr = next2MASSfield (ptr); // j_m
    30   star[0][0].M  = strtod (ptr, NULL);
     30  star[0][0].measure.M  = strtod (ptr, NULL);
    3131  ptr = next2MASSfield (ptr); // j_cmsig
    32   star[0][0].dM = strtod (ptr, NULL);
     32  star[0][0].measure.dM = strtod (ptr, NULL);
    3333  ptr = next2MASSfield (ptr); // j_msigcom
    3434  dMfull = strtod (ptr, NULL);
    35   star[0][0].dMcal = sqrt (SQ(dMfull) - SQ(star[0][0].dM));
     35  star[0][0].measure.dMcal = sqrt (SQ(dMfull) - SQ(star[0][0].measure.dM));
    3636  ptr = next2MASSfield (ptr); // j_snr (skip)
    3737
    3838  ptr = next2MASSfield (ptr); // h_m
    39   star[1][0].M  = strtod (ptr, NULL);
     39  star[1][0].measure.M  = strtod (ptr, NULL);
    4040  ptr = next2MASSfield (ptr); // h_cmsig
    41   star[1][0].dM = strtod (ptr, NULL);
     41  star[1][0].measure.dM = strtod (ptr, NULL);
    4242  ptr = next2MASSfield (ptr); // h_msigcom
    4343  dMfull = strtod (ptr, NULL);
    44   star[1][0].dMcal = sqrt (SQ(dMfull) - SQ(star[1][0].dM));
     44  star[1][0].measure.dMcal = sqrt (SQ(dMfull) - SQ(star[1][0].measure.dM));
    4545  ptr = next2MASSfield (ptr); // h_snr (skip)
    4646
    4747  ptr = next2MASSfield (ptr); // k_m
    48   star[2][0].M  = strtod (ptr, NULL);
     48  star[2][0].measure.M  = strtod (ptr, NULL);
    4949  ptr = next2MASSfield (ptr); // k_cmsig
    50   star[2][0].dM = strtod (ptr, NULL);
     50  star[2][0].measure.dM = strtod (ptr, NULL);
    5151  ptr = next2MASSfield (ptr); // k_msigcom
    5252  dMfull = strtod (ptr, NULL);
    53   star[2][0].dMcal = sqrt (SQ(dMfull) - SQ(star[2][0].dM));
     53  star[2][0].measure.dMcal = sqrt (SQ(dMfull) - SQ(star[2][0].measure.dM));
    5454  ptr = next2MASSfield (ptr); // k_snr (skip)
    5555
    56   star[2][0].flags = star[1][0].flags = star[0][0].flags = 0;
     56  star[2][0].measure.photFlags = star[1][0].measure.photFlags = star[0][0].measure.photFlags = 0;
    5757
    5858  ptr = next2MASSfield (ptr); // ph_qual
     
    9999
    100100  ptr = next2MASSfield (ptr); // x_scan
    101   star[0][0].X = strtod (ptr, NULL);
    102   star[2][0].X = star[1][0].X = star[0][0].X;
     101  star[0][0].measure.Xccd = strtod (ptr, NULL);
     102  star[2][0].measure.Xccd = star[1][0].measure.Xccd = star[0][0].measure.Xccd;
    103103
    104104  ptr = next2MASSfield (ptr); // jdate (julian date)
    105105  jd = strtod (ptr, NULL);
    106   star[0][0].t = ohana_jd_to_sec (jd);
    107   star[2][0].t = star[1][0].t = star[0][0].t;
     106  star[0][0].measure.t = ohana_jd_to_sec (jd);
     107  star[2][0].measure.t = star[1][0].measure.t = star[0][0].measure.t;
    108108
    109109  ptr = next2MASSfield (ptr); // j_psfchi
    110   star[0][0].psfChisq = strtod (ptr, NULL);
     110  star[0][0].measure.psfChisq = strtod (ptr, NULL);
    111111  ptr = next2MASSfield (ptr); // h_psfchi
    112   star[1][0].psfChisq = strtod (ptr, NULL);
     112  star[1][0].measure.psfChisq = strtod (ptr, NULL);
    113113  ptr = next2MASSfield (ptr); // k_psfchi
    114   star[2][0].psfChisq = strtod (ptr, NULL);
     114  star[2][0].measure.psfChisq = strtod (ptr, NULL);
    115115
    116116  ptr = next2MASSfield (ptr); // j_m_stdap
    117   star[0][0].Map = strtod (ptr, NULL);
     117  star[0][0].measure.Map = strtod (ptr, NULL);
    118118  ptr = next2MASSfield (ptr); // j_msig_stdap (skip?)
    119119
    120120  ptr = next2MASSfield (ptr); // h_m_stdap
    121   star[1][0].Map = strtod (ptr, NULL);
     121  star[1][0].measure.Map = strtod (ptr, NULL);
    122122  ptr = next2MASSfield (ptr); // h_msig_stdap (skip?)
    123123
    124124  ptr = next2MASSfield (ptr); // k_m_stdap
    125   star[2][0].Map = strtod (ptr, NULL);
     125  star[2][0].measure.Map = strtod (ptr, NULL);
    126126  ptr = next2MASSfield (ptr); // k_msig_stdap (skip?)
    127127
     
    140140  set2MASS_use_flag (star[2], ptr[0]);
    141141
    142   star[0][0].code  = TM_J;
    143   star[0][0].found = -1;
    144   star[0][0].detID   = 0;
    145   star[0][0].imageID = 0;
    146 
    147   star[1][0].code  = TM_H;
    148   star[1][0].found = -1;
    149   star[1][0].detID   = 0;
    150   star[1][0].imageID = 0;
    151 
    152   star[2][0].code  = TM_K;
    153   star[2][0].found = -1;
    154   star[2][0].detID   = 0;
    155   star[2][0].imageID = 0;
     142  star[0][0].measure.photcode  = TM_J;
     143  star[0][0].measure.detID   = 0;
     144  star[0][0].measure.imageID = 0;
     145
     146  star[1][0].measure.photcode  = TM_H;
     147  star[1][0].measure.detID   = 0;
     148  star[1][0].measure.imageID = 0;
     149
     150  star[2][0].measure.photcode  = TM_K;
     151  star[2][0].measure.detID   = 0;
     152  star[2][0].measure.imageID = 0;
    156153
    157154  return TRUE;
     
    174171
    175172  switch (qual) {
    176     case 'X': star[0].flags |= 0x0000; break;
    177     case 'U': star[0].flags |= 0x0001; break;
    178     case 'F': star[0].flags |= 0x0002; break;
    179     case 'E': star[0].flags |= 0x0003; break;
    180     case 'A': star[0].flags |= 0x0004; break;
    181     case 'B': star[0].flags |= 0x0005; break;
    182     case 'C': star[0].flags |= 0x0006; break;
    183     case 'D': star[0].flags |= 0x0007; break;
     173    case 'X': star[0].measure.photFlags |= 0x0000; break;
     174    case 'U': star[0].measure.photFlags |= 0x0001; break;
     175    case 'F': star[0].measure.photFlags |= 0x0002; break;
     176    case 'E': star[0].measure.photFlags |= 0x0003; break;
     177    case 'A': star[0].measure.photFlags |= 0x0004; break;
     178    case 'B': star[0].measure.photFlags |= 0x0005; break;
     179    case 'C': star[0].measure.photFlags |= 0x0006; break;
     180    case 'D': star[0].measure.photFlags |= 0x0007; break;
    184181    default:
    185182      fprintf (stderr, "error!\n");
     
    192189
    193190  switch (qual) {
    194     case '0': star[0].flags |= 0x0000; break;
    195     case '1': star[0].flags |= 0x0010; break;
    196     case '2': star[0].flags |= 0x0020; break;
    197     case '3': star[0].flags |= 0x0030; break;
    198     case '4': star[0].flags |= 0x0040; break;
    199     case '6': star[0].flags |= 0x0050; break;
    200     case '9': star[0].flags |= 0x0060; break;
     191    case '0': star[0].measure.photFlags |= 0x0000; break;
     192    case '1': star[0].measure.photFlags |= 0x0010; break;
     193    case '2': star[0].measure.photFlags |= 0x0020; break;
     194    case '3': star[0].measure.photFlags |= 0x0030; break;
     195    case '4': star[0].measure.photFlags |= 0x0040; break;
     196    case '6': star[0].measure.photFlags |= 0x0050; break;
     197    case '9': star[0].measure.photFlags |= 0x0060; break;
    201198    default:
    202199      fprintf (stderr, "error!\n");
     
    209206
    210207  switch (qual) {
    211     case 'p': star[0].flags |= 0x0000; break;
    212     case 'c': star[0].flags |= 0x0100; break;
    213     case 'd': star[0].flags |= 0x0200; break;
    214     case 's': star[0].flags |= 0x0300; break;
    215     case 'b': star[0].flags |= 0x0400; break;
    216     case '0': star[0].flags |= 0x0500; break;
     208    case 'p': star[0].measure.photFlags |= 0x0000; break;
     209    case 'c': star[0].measure.photFlags |= 0x0100; break;
     210    case 'd': star[0].measure.photFlags |= 0x0200; break;
     211    case 's': star[0].measure.photFlags |= 0x0300; break;
     212    case 'b': star[0].measure.photFlags |= 0x0400; break;
     213    case '0': star[0].measure.photFlags |= 0x0500; break;
    217214    default:
    218215      fprintf (stderr, "error!\n");
     
    225222
    226223  switch (qual) {
    227     case '0': star[0].flags &= ~0x0008; break;
    228     case '1': star[0].flags &= ~0x0008; break;
    229     default:  star[0].flags |=  0x0008; break;
     224    case '0': star[0].measure.photFlags &= ~0x0008; break;
     225    case '1': star[0].measure.photFlags &= ~0x0008; break;
     226    default:  star[0].measure.photFlags |=  0x0008; break;
    230227  }     
    231228  return (TRUE);
     
    235232
    236233  switch (qual) {
    237     case '0': star[0].flags &= ~0x0080; break;
    238     case '1': star[0].flags &= ~0x0080; break;
     234    case '0': star[0].measure.photFlags &= ~0x0080; break;
     235    case '1': star[0].measure.photFlags &= ~0x0080; break;
    239236    default: 
    240       star[0].flags |= 0x0080;
    241       star[0].extNsigma = 100.0;
     237      star[0].measure.photFlags |= 0x0080;
     238      star[0].measure.extNsigma = 100.0;
    242239      break;
    243240  }     
     
    248245
    249246  switch (qual) {
    250     case '0': star[0].flags &= ~0x0800; break;
    251     case '1': star[0].flags &= ~0x0800; break;
    252     default:  star[0].flags |=  0x0800; break;
     247    case '0': star[0].measure.photFlags &= ~0x0800; break;
     248    case '1': star[0].measure.photFlags &= ~0x0800; break;
     249    default:  star[0].measure.photFlags |=  0x0800; break;
    253250  }     
    254251  return (TRUE);
     
    258255
    259256  switch (qual) {
    260     case '0': star[0].flags &= ~0x1000; break;
    261     case '1': star[0].flags &= ~0x1000; break;
    262     default:  star[0].flags |=  0x1000; break;
     257    case '0': star[0].measure.photFlags &= ~0x1000; break;
     258    case '1': star[0].measure.photFlags &= ~0x1000; break;
     259    default:  star[0].measure.photFlags |=  0x1000; break;
    263260  }     
    264261  return (TRUE);
     
    268265
    269266  switch (qual) {
    270     case '0': star[0].flags &= ~0x2000; break;
    271     case '1': star[0].flags |=  0x2000; break;
     267    case '0': star[0].measure.photFlags &= ~0x2000; break;
     268    case '1': star[0].measure.photFlags |=  0x2000; break;
    272269    default:  abort();
    273270  }     
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/get2mass_ops.c

    r17196 r21536  
    4242  double M, dM;
    4343  e_time time;
     44
     45  InitStar (star);
    4446
    4547  ptr = skipNbounds (line, '|', FilterSkip, Nmax);
     
    5759  }
    5860
    59   star[0].M       = M;
    60   star[0].dM      = dM;
    61   star[0].code    = Photcode;
    62   star[0].t       = time;
    63   star[0].found   = -1;
    64   star[0].detID   = 0;
    65   star[0].imageID = 0;
     61  star[0].measure.M        = M;
     62  star[0].measure.dM       = dM;
     63  star[0].measure.photcode = Photcode;
     64  star[0].measure.t        = time;
     65  star[0].measure.detID    = 0;
     66  star[0].measure.imageID  = 0;
    6667
    6768  return TRUE;
     
    107108  // how many bits are being used for the 2mass flags; can we just set photFlags based on them?
    108109
    109   star[0].M     = J;
    110   star[0].dM    = dJ;
    111   star[0].code  = TM_J;
    112   star[0].t     = time;
    113   star[0].found = -1;
    114   star[0].detID   = 0;
    115   star[0].imageID = 0;
    116 
    117   star[1].M     = H;
    118   star[1].dM    = dH;
    119   star[1].code  = TM_H;
    120   star[1].t     = time;
    121   star[1].found = -1;
    122   star[1].detID   = 0;
    123   star[1].imageID = 0;
    124 
    125   star[2].M     = K;
    126   star[2].dM    = dK;
    127   star[2].code  = TM_K;
    128   star[2].t     = time;
    129   star[2].found = -1;
    130   star[2].detID   = 0;
    131   star[2].imageID = 0;
     110  star[0].measure.M         = J;
     111  star[0].measure.dM        = dJ;
     112  star[0].measure.photcode  = TM_J;
     113  star[0].measure.t         = time;
     114  star[0].measure.detID     = 0;
     115  star[0].measure.imageID   = 0;
     116
     117  star[1].measure.M         = H;
     118  star[1].measure.dM        = dH;
     119  star[1].measure.photcode  = TM_H;
     120  star[1].measure.t         = time;
     121  star[1].measure.detID     = 0;
     122  star[1].measure.imageID   = 0;
     123
     124  star[2].measure.M         = K;
     125  star[2].measure.dM        = dK;
     126  star[2].measure.photcode  = TM_K;
     127  star[2].measure.t         = time;
     128  star[2].measure.detID     = 0;
     129  star[2].measure.imageID   = 0;
    132130
    133131  return TRUE;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/getgsc.c

    r17439 r21536  
    6767    Nline = nbytes / BYTES_STAR;
    6868    for (i = 0; i < Nline; i++) {
     69
     70      InitStar (&stars[Nstars]);
     71
    6972      Nbyte = i*BYTES_STAR;
    70       dparse (&stars[Nstars].R, 1, &buffer[Nbyte]);
    71       dparse (&stars[Nstars].D, 2, &buffer[Nbyte]);
    72       if (stars[Nstars].R < UserPatch.Rmin) continue;
    73       if (stars[Nstars].R > UserPatch.Rmax) continue;
    74       if (stars[Nstars].D < UserPatch.Dmin) continue;
    75       if (stars[Nstars].D > UserPatch.Dmax) continue;
     73      dparse (&stars[Nstars].average.R, 1, &buffer[Nbyte]);
     74      dparse (&stars[Nstars].average.D, 2, &buffer[Nbyte]);
    7675
    77       dparse (&stars[Nstars].M, 3, &buffer[Nbyte]);
    78       stars[Nstars].dM    = NAN;
    79       stars[Nstars].t     = 0;
    80       stars[Nstars].code  = GSC_M;
    81       stars[Nstars].found = -1;
     76      if (stars[Nstars].average.R < UserPatch.Rmin) continue;
     77      if (stars[Nstars].average.R > UserPatch.Rmax) continue;
     78      if (stars[Nstars].average.D < UserPatch.Dmin) continue;
     79      if (stars[Nstars].average.D > UserPatch.Dmax) continue;
    8280
    83       stars[Nstars].detID   = 0;
    84       stars[Nstars].imageID = 0;
    85 
    86       stars[Nstars].X  = 0;
    87       stars[Nstars].Y  = 0;
    88       stars[Nstars].fx = 0;
    89       stars[Nstars].fy = 0;
    90       stars[Nstars].df = 0;
     81      fparse (&stars[Nstars].measure.M, 3, &buffer[Nbyte]);
     82      stars[Nstars].measure.dM        = NAN;
     83      stars[Nstars].measure.photcode  = GSC_M;
     84      stars[Nstars].measure.t         = 0;
    9185
    9286      Nstars ++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/gettycho.c

    r17439 r21536  
    6969
    7070      for (j = 0; j < nitems; j++) {
     71
    7172        line = &buffer[j*NBYTE];
    72         stars[Ntycho].R = atof (&line[15]);
    73         stars[Ntycho].D = atof (&line[28]);
    7473
    75         if (stars[Ntycho].R < region[0].Rmin) goto next_section;
    76         if (stars[Ntycho].R > region[0].Rmax) goto next_section;
    77         if (stars[Ntycho].D < region[0].Dmin) goto next_section;
    78         if (stars[Ntycho].D > region[0].Dmax) goto next_section;
     74        InitStar (&stars[Ntycho]);
    7975
    80         if (stars[Ntycho].R < UserPatch.Rmin) continue;
    81         if (stars[Ntycho].R > UserPatch.Rmax) continue;
    82         if (stars[Ntycho].D < UserPatch.Dmin) continue;
    83         if (stars[Ntycho].D > UserPatch.Dmax) continue;
     76        stars[Ntycho].average.R = atof (&line[15]);
     77        stars[Ntycho].average.D = atof (&line[28]);
    8478
    85         stars[Ntycho].dR  = 1000 * atof (&line[57]);
    86         stars[Ntycho].dD  = 1000 * atof (&line[64]);
     79        if (stars[Ntycho].average.R < region[0].Rmin) goto next_section;
     80        if (stars[Ntycho].average.R > region[0].Rmax) goto next_section;
     81        if (stars[Ntycho].average.D < region[0].Dmin) goto next_section;
     82        if (stars[Ntycho].average.D > region[0].Dmax) goto next_section;
     83
     84        if (stars[Ntycho].average.R < UserPatch.Rmin) continue;
     85        if (stars[Ntycho].average.R > UserPatch.Rmax) continue;
     86        if (stars[Ntycho].average.D < UserPatch.Dmin) continue;
     87        if (stars[Ntycho].average.D > UserPatch.Dmax) continue;
     88
     89        stars[Ntycho].average.dR  = 1000 * atof (&line[57]);
     90        stars[Ntycho].average.dD  = 1000 * atof (&line[64]);
    8791
    8892        /* XXX : we need to apply uR,uD to R,D to advance to 2000.0 */
    89         stars[Ntycho].uR  = atof (&line[41]);
    90         stars[Ntycho].uD  = atof (&line[49]);
     93        stars[Ntycho].average.uR  = atof (&line[41]);
     94        stars[Ntycho].average.uD  = atof (&line[49]);
    9195
    92         stars[Ntycho].duR = atof (&line[69]);
    93         stars[Ntycho].duD = atof (&line[75]);
    94        
    95         stars[Ntycho].P   = 0;
    96         stars[Ntycho].dP  = 0;
    97 
    98         stars[Ntycho].detID   = 0;
    99         stars[Ntycho].imageID = 0;
     96        stars[Ntycho].average.duR = atof (&line[69]);
     97        stars[Ntycho].average.duD = atof (&line[75]);
    10098
    10199        /* Tycho uses J2000 equinox and 1991.25 epoch for coordinates */
    102100        /* the magnitudes have no temporal information */
    103         stars[Ntycho].t   = TychoEpoch;
    104         stars[Ntycho].found = -1;
    105      
    106         stars[Ntycho].X  = 0;
    107         stars[Ntycho].Y  = 0;
    108         stars[Ntycho].fx = 0;
    109         stars[Ntycho].fy = 0;
    110         stars[Ntycho].df = 0;
     101        stars[Ntycho].measure.t   = TychoEpoch;
    111102
    112103        /* one pass of addstar does either r or b */
    113104        if (photcode == TYCHO_B) {
    114           stars[Ntycho].M    = atof (&line[110]);
    115           stars[Ntycho].dM    = atof (&line[117]);
    116           stars[Ntycho].code = TYCHO_B;
     105          stars[Ntycho].measure.M        = atof (&line[110]);
     106          stars[Ntycho].measure.dM      = atof (&line[117]);
     107          stars[Ntycho].measure.photcode = TYCHO_B;
    117108        } else {
    118           stars[Ntycho].M    = atof (&line[123]);
    119           stars[Ntycho].dM    = atof (&line[130]);
    120           stars[Ntycho].code = TYCHO_V;
     109          stars[Ntycho].measure.M        = atof (&line[123]);
     110          stars[Ntycho].measure.dM      = atof (&line[130]);
     111          stars[Ntycho].measure.photcode = TYCHO_V;
    121112        }       
    122113     
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/getusno.c

    r17439 r21536  
    110110      if (buf[1] > iDEC1) continue;
    111111
    112       memset (&stars[Nusno], 0, sizeof(Stars));
    113       stars[Nusno].R     = buf[0]/360000.0;
    114       stars[Nusno].D     = buf[1]/360000.0 - 90.0;
    115       stars[Nusno].dM    = NAN;
    116       stars[Nusno].t     = 0;
    117       stars[Nusno].found = -1;
     112      InitStar (&stars[Nusno]);
    118113
    119       stars[Nusno].detID   = 0;
    120       stars[Nusno].imageID = 0;
    121 
    122       stars[Nusno].X  = 0;
    123       stars[Nusno].Y  = 0;
    124       stars[Nusno].fx = 0;
    125       stars[Nusno].fy = 0;
    126       stars[Nusno].df = 0;
     114      stars[Nusno].average.R     = buf[0]/360000.0;
     115      stars[Nusno].average.D     = buf[1]/360000.0 - 90.0;
     116      stars[Nusno].measure.dM    = NAN;
    127117
    128118      /* one pass of addstar does either r or b */
    129119      if (photcode == USNO_RED) {
    130         stars[Nusno].code = USNO_RED;
    131         stars[Nusno].M     = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000))));
     120        stars[Nusno].measure.photcode = USNO_RED;
     121        stars[Nusno].measure.M        = fabs (0.1*(buf[2] - 1000*((int)(buf[2]/1000))));
    132122      }
    133123      if (photcode == USNO_BLUE) {     
    134         stars[Nusno].code = USNO_BLUE;
    135         stars[Nusno].M     = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000));
     124        stars[Nusno].measure.photcode = USNO_BLUE;
     125        stars[Nusno].measure.M        = fabs (0.1*((int)(buf[2] - 1000000*((int)(buf[2]/1000000))) / 1000));
    136126      }
    137127      Nusno ++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/getusnob.c

    r17439 r21536  
    125125      /* USNO coords are reported for J2000 / epoch 2000.0 */
    126126      /* extract the basic stellar data */
    127       memset (&stars[Nusno], 0, sizeof(Stars));
    128       stars[Nusno].R   = buf[0]/360000.0;
    129       stars[Nusno].D   = buf[1]/360000.0 - 90.0;
     127      InitStar (&stars[Nusno]);
     128
     129      stars[Nusno].average.R   = buf[0]/360000.0;
     130      stars[Nusno].average.D   = buf[1]/360000.0 - 90.0;
    130131
    131132      /* XXX uR cos(D) or just uR ??? */
    132       stars[Nusno].uR  = 2.0 * ((buf[2]       % 10000) - 5000);
    133       stars[Nusno].uD  = 2.0 * ((buf[2]/10000 % 10000) - 5000);
     133      stars[Nusno].average.uR  = 2.0 * ((buf[2]       % 10000) - 5000);
     134      stars[Nusno].average.uD  = 2.0 * ((buf[2]/10000 % 10000) - 5000);
    134135
    135       stars[Nusno].duR = (buf[3]      % 1000);
    136       stars[Nusno].duD = (buf[3]/1000 % 1000);
     136      stars[Nusno].average.duR = (buf[3]      % 1000);
     137      stars[Nusno].average.duD = (buf[3]/1000 % 1000);
    137138
    138       stars[Nusno].dR  = 0.001 * (buf[4]      % 1000);
    139       stars[Nusno].dD  = 0.001 * (buf[4]/1000 % 1000);
     139      stars[Nusno].average.dR  = 0.001 * (buf[4]      % 1000);
     140      stars[Nusno].average.dD  = 0.001 * (buf[4]/1000 % 1000);
    140141
    141       stars[Nusno].P   = 0;
    142       stars[Nusno].dP  = 0;
     142      stars[Nusno].average.P   = 0;
     143      stars[Nusno].average.dP  = 0;
    143144
    144145      /* USNO magnitude errors are reported as a fixed 0.3 mag */
    145       stars[Nusno].dM    = 0.3;
    146       stars[Nusno].found = -1;
    147      
    148       stars[Nusno].detID   = 0;
    149       stars[Nusno].imageID = 0;
    150 
    151       stars[Nusno].X  = 0;
    152       stars[Nusno].Y  = 0;
    153       stars[Nusno].fx = 0;
    154       stars[Nusno].fy = 0;
    155       stars[Nusno].df = 0;
     146      stars[Nusno].measure.dM  = 0.3;
    156147
    157148      /* USNO-B uses J2000 equinox and 2000.0 epoch for coordinates */
    158149      /* the magnitudes have no temporal information */
    159       stars[Nusno].   = USNOepoch;
     150      stars[Nusno].measure.t   = USNOepoch;
    160151
    161152      /* one pass of addstar does r, b, or n */
     
    172163          m2 = 0;
    173164      }
    174       stars[Nusno].code = photcode;
     165      stars[Nusno].measure.photcode = photcode;
    175166
    176167      /* if two mags are available, get an average */
     
    180171        mag = (m1) ? m1 : m2;
    181172      }
    182       stars[Nusno].M = (mag == 0.0) ? 32.0 : mag;
     173      stars[Nusno].measure.M = (mag == 0.0) ? 32.0 : mag;
    183174
    184175      Nusno ++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/greference.c

    r6683 r21536  
    33# define LOAD_DR2    1
    44
    5 Stars *grefcat (char *Refcat, SkyRegion *region, int photcode, int *nstars) {
     5Stars *greference (char *Refcat, SkyRegion *region, int photcode, int *nstars) {
    66
    77  int Nstars;
     
    3636  /* get stars from 2MASS for the given region */
    3737  if (!strcasecmp (Refcat, "2MASS")) {
    38     stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
     38    // stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
     39    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
     40    exit (2);
    3941  }
    4042 
    4143  /* get stars from 2MASS for the given region */
    4244  if (!strcasecmp (Refcat, "2MASS-ALLSKY")) {
    43     stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
     45    // stars = get2mass (region, photcode, LOAD_ALLSKY, &Nstars);
     46    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
     47    exit (2);
    4448  }
    4549 
    4650  /* get stars from 2MASS for the given region */
    4751  if (!strcasecmp (Refcat, "2MASS-DR2")) {
    48     stars = get2mass (region, photcode, LOAD_DR2, &Nstars);
     52    // stars = get2mass (region, photcode, LOAD_DR2, &Nstars);
     53    fprintf (stderr, "2MASS load via addstar is deprecated: use load2mass\n");
     54    exit (2);
    4955  }
    5056 
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/grefstars.c

    r19823 r21536  
    2121    if (line[0] == 0) continue;
    2222    if (line[0] == '#') continue;
    23     dparse (&stars[N].R,  1, line);
    24     dparse (&stars[N].D,  2, line);
    25     dparse (&stars[N].M,  3, line);
    26     dparse (&stars[N].dM, 4, line);
    27     stars[N].R = ohana_normalize_angle (stars[N].R);
    28     stars[N].t = 0;
    29     stars[N].code = photcode;
    30     stars[N].found = FALSE;
    31     stars[N].detID   = 0;
    32     stars[N].imageID = 0;
    3323
    34     stars[N].X  = 0;
    35     stars[N].Y  = 0;
    36     stars[N].fx = 0;
    37     stars[N].fy = 0;
    38     stars[N].df = 0;
     24    InitStar (&stars[N]);
     25
     26    dparse (&stars[N].average.R,  1, line);
     27    dparse (&stars[N].average.D,  2, line);
     28    stars[N].average.R = ohana_normalize_angle (stars[N].average.R);
     29
     30    fparse (&stars[N].measure.M,  3, line);
     31    fparse (&stars[N].measure.dM, 4, line);
     32
     33    stars[N].measure.photcode = photcode;
    3934
    4035    CHECK_REALLOCATE (stars, Stars, NSTARS, N+1, 100);
     
    4338  return (stars);
    4439}
    45 
    46 /* stars.found is set here to FALSE.
    47    find_match_refstars uses stars.found to identify the seq number of the
    48    star which is found.  it requires an initial value of -1 XXX
    49 */
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/load2mass_as_rawdata.c

    r17439 r21536  
    140140        ALLOCATE (stars[Nstars+2], Stars, 1);
    141141
    142         stars[Nstars+0][0].R = tstars[j].R;
    143         stars[Nstars+0][0].D = tstars[j].D;
    144         stars[Nstars+1][0].R = tstars[j].R;
    145         stars[Nstars+1][0].D = tstars[j].D;
    146         stars[Nstars+2][0].R = tstars[j].R;
    147         stars[Nstars+2][0].D = tstars[j].D;
     142        InitStar (stars[Nstars+0]);
     143        InitStar (stars[Nstars+1]);
     144        InitStar (stars[Nstars+2]);
     145
     146        stars[Nstars+0][0].average.R = tstars[j].R;
     147        stars[Nstars+0][0].average.D = tstars[j].D;
     148        stars[Nstars+1][0].average.R = tstars[j].R;
     149        stars[Nstars+1][0].average.D = tstars[j].D;
     150        stars[Nstars+2][0].average.R = tstars[j].R;
     151        stars[Nstars+2][0].average.D = tstars[j].D;
    148152        get2mass_3star_full (&stars[Nstars], &buffer[offset], Nbyte - offset);
    149         // get2mass_star (&stars[Nstars], &buffer[offset], Nbyte - offset);
    150153
    151154        tstars[j].flag = TRUE;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/load2mass_catalog.c

    r16810 r21536  
    2020    // XXX for now, the output objects will have limited astrometric interpretation...
    2121    // XXX every 3 stars represents 3 measurements and 1 average
    22     catalog[0].average[Nave].R     = stars[i].R;
    23     catalog[0].average[Nave].D     = stars[i].D;
     22    catalog[0].average[Nave].R     = stars[i].average.R;
     23    catalog[0].average[Nave].D     = stars[i].average.D;
    2424    catalog[0].average[Nave].dR    = 0;
    2525    catalog[0].average[Nave].dD    = 0;
     
    3737    catalog[0].average[Nave].measureOffset = Nmeas;
    3838    catalog[0].average[Nave].missingOffset = -1;
    39     catalog[0].average[Nave].code          = 0;
     39    catalog[0].average[Nave].flags         = 0;
    4040
    4141    for (j = 0; j < Nsec; j++) {
    42       catalog[0].secfilt[Nave*Nsec+j].M  = NAN;
    43       catalog[0].secfilt[Nave*Nsec+j].dM = NAN;
    44       catalog[0].secfilt[Nave*Nsec+j].Xm = NAN_S_SHORT;
     42      catalog[0].secfilt[Nave*Nsec+j].M     = NAN;
     43      catalog[0].secfilt[Nave*Nsec+j].dM    = NAN;
     44      catalog[0].secfilt[Nave*Nsec+j].Xm    = NAN_S_SHORT;
     45      catalog[0].secfilt[Nave*Nsec+j].M_20  = NAN_S_SHORT;
     46      catalog[0].secfilt[Nave*Nsec+j].M_80  = NAN_S_SHORT;
     47      catalog[0].secfilt[Nave*Nsec+j].Ncode = 0;
     48      catalog[0].secfilt[Nave*Nsec+j].Nused = 0;
    4549    }
    4650
    4751    // we now have the min chisq row. use this to supply the other filter values....
    4852    for (j = 0; j < 3; j++) {
     53      catalog[0].measure[Nmeas]           = stars[i+j].measure;
     54
    4955      catalog[0].measure[Nmeas].dR        = 0.0;
    5056      catalog[0].measure[Nmeas].dD        = 0.0;
    51       catalog[0].measure[Nmeas].Xccd      = stars[i+j].X;
    52       catalog[0].measure[Nmeas].Yccd      = stars[i+j].Y;
    53       catalog[0].measure[Nmeas].dXccd     = 0.0;
    54       catalog[0].measure[Nmeas].dYccd     = 0.0;
    55       catalog[0].measure[Nmeas].M         = stars[i+j].M;
    56       catalog[0].measure[Nmeas].dM        = stars[i+j].dM;
    57       catalog[0].measure[Nmeas].Mcal      = 0;
    58       catalog[0].measure[Nmeas].dMcal     = stars[i+j].dMcal;
    59       catalog[0].measure[Nmeas].t         = stars[i+j].t;
    60       catalog[0].measure[Nmeas].averef    = Nave;
    61       catalog[0].measure[Nmeas].photcode  = stars[i+j].code;
    62       catalog[0].measure[Nmeas].dophot    = 0;
    63       catalog[0].measure[Nmeas].photFlags = stars[i+j].flags;
    64       catalog[0].measure[Nmeas].dbFlags   = 0;
    65       catalog[0].measure[Nmeas].dt        = 0xffff;
    66                                          
    67       catalog[0].measure[Nmeas].airmass   = 0;
    68       catalog[0].measure[Nmeas].FWx       = stars[i+j].fx;
    69       catalog[0].measure[Nmeas].FWy       = stars[i+j].fy;
    70       catalog[0].measure[Nmeas].theta     = stars[i+j].df;
     57      catalog[0].measure[Nmeas].dt        = NAN_S_SHORT;
     58
     59      // XXX what about averef?
    7160
    7261      catalog[0].average[Nave].Nmeasure++;
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/replace_match.c

    r16810 r21536  
    77  /* search for entry and replace values M, dM, R, D */
    88  for (i = 0; i < average[0].Nmeasure; i++) {
    9     if (measure[i].photcode != star[0].code) continue;
    10     measure[i].dR = 3600.0*(average[0].R - star[0].R);
    11     measure[i].dD = 3600.0*(average[0].D - star[0].D);
    12     measure[i].M  = star[0].M;
    13     measure[i].dM = star[0].dM;
     9    if (measure[i].photcode != star[0].measure.photcode) continue;
     10    measure[i].dR = 3600.0*(average[0].R - star[0].average.R);
     11    measure[i].dD = 3600.0*(average[0].D - star[0].average.D);
     12    measure[i].M  = star[0].measure.M;
     13    measure[i].dM = star[0].measure.dM;
    1414    star[0].found = average[0].measureOffset + i;
    1515    return (TRUE);
  • branches/cnb_branch_20090215/Ohana/src/addstar/src/sky_tessalation.c

    r21055 r21536  
    281281  image[0].NY = NY;
    282282
    283   image[0].code = 1; // this needs to be set more sensibly
     283  image[0].photcode = 1; // this needs to be set more sensibly
    284284
    285285  image[0].Mx   = xv[0];  image[0].My   = yv[0];
     
    433433  rectangle[0].NX = NX;
    434434  rectangle[0].NY = NY;
    435   rectangle[0].code = 1; // this needs to be set more sensibly
     435  rectangle[0].photcode = 1; // this needs to be set more sensibly
    436436
    437437  return (TRUE);
     
    477477  rectangle[0].NX = NX;
    478478  rectangle[0].NY = NY;
    479   rectangle[0].code = 1; // this needs to be set more sensibly
     479  rectangle[0].photcode = 1; // this needs to be set more sensibly
    480480
    481481  return (TRUE);
     
    511511      output[N].NX = NX;
    512512      output[N].NY = NY;
    513       output[N].code = input[0].code;
     513      output[N].photcode = input[0].photcode;
    514514
    515515      output[N].coords.crpix1 = input[0].coords.crpix1 - i*NX;
  • branches/cnb_branch_20090215/Ohana/src/getstar/src/ReadImageFiles.c

    r19259 r21536  
    6464      /* find image rootname */
    6565      name = filebasename (file[i]);
    66       snprintf (image[N].name, DVO_IMAGE_NAME_LEN, name);
     66      snprintf (image[N].name, DVO_IMAGE_NAME_LEN, "%s", name);
    6767      free (name);
    6868
  • branches/cnb_branch_20090215/Ohana/src/getstar/src/ReadImageHeader.c

    r20184 r21536  
    112112  image[0].Mcal = 0.0;
    113113  image[0].Xm   = NAN_S_SHORT;
    114   image[0].code = 0;
     114  image[0].flags = 0;
    115115
    116116  return (TRUE);
  • branches/cnb_branch_20090215/Ohana/src/getstar/src/write_getstar_ps1_dev_0.c

    r16810 r21536  
    4646    output[i].D        = average[i].D;
    4747
    48     output[i].code     = average[i].code;
     48    output[i].code     = average[i].flags;
    4949    output[i].photcode = code_c0;
    5050
  • branches/cnb_branch_20090215/Ohana/src/getstar/src/write_getstar_ps1_dev_1.c

    r16810 r21536  
    4949    output[i].P        = average[i].P;
    5050
    51     output[i].code     = average[i].code;
     51    output[i].code     = average[i].flags;
    5252    output[i].photcode = code_c0;
    5353
  • branches/cnb_branch_20090215/Ohana/src/getstar/src/write_getstar_ps1_dev_2.c

    r16810 r21536  
    5555    output[i].dP       = average[i].dP;
    5656
    57     output[i].code     = average[i].code;
     57    output[i].code     = average[i].flags;
    5858    output[i].photcode = code_c0;
    5959
  • branches/cnb_branch_20090215/Ohana/src/imregister/imphot/modify.c

    r7080 r21536  
    1313    if (options.modify) {
    1414      if (!strcasecmp (options.ModifyEntry, "and")) {
    15         image[i].code &= atoi (options.ModifyValue);
     15        image[i].flags &= atoi (options.ModifyValue);
    1616      }
    1717      if (!strcasecmp (options.ModifyEntry, "or")) {
    18         image[i].code |= atoi (options.ModifyValue);
     18        image[i].flags |= atoi (options.ModifyValue);
    1919      }
    2020      if (!strcasecmp (options.ModifyEntry, "xor")) {
    21         image[i].code ^= atoi (options.ModifyValue);
     21        image[i].flags ^= atoi (options.ModifyValue);
    2222      }
    2323      if (!strcasecmp (options.ModifyEntry, "=")) {
    24         image[i].code = atoi (options.ModifyValue);
     24        image[i].flags = atoi (options.ModifyValue);
    2525      }
    2626    }
  • branches/cnb_branch_20090215/Ohana/src/imregister/imphot/output.c

    r14590 r21536  
    3939     
    4040    fprintf (stdout, "%s %s %s  %7.4f %7.4f  %7.4f %5d %02x\n", image[i].name, photstr, timestr,
    41              image[i].Mcal, image[i].dMcal, image[i].secz, image[i].nstar, image[i].code);
     41             image[i].Mcal, image[i].dMcal, image[i].secz, image[i].nstar, image[i].flags);
    4242    free (timestr);
    4343  }
  • branches/cnb_branch_20090215/Ohana/src/imregister/imphot/subset.c

    r12332 r21536  
    2424    if (!status && criteria.Ntimes) continue;
    2525    if (criteria.PhotcodeSelect && (image[i].photcode != criteria.photcode)) continue;
    26     if (criteria.CodeSelect     && (image[i].code != criteria.Code)) continue;
     26    if (criteria.CodeSelect     && (image[i].flags != criteria.Code)) continue;
    2727    if (criteria.NameSelect     && strncasecmp (image[i].name, criteria.Name, NameSelectLength)) continue;
    2828
  • branches/cnb_branch_20090215/Ohana/src/libautocode/Makefile.Targets

    r19185 r21536  
    1 
    21AOBJS = \
    32$(ASRC)/coords.$(ARCH).o \
     
    98$(ASRC)/average-ps1-dev-1.$(ARCH).o \
    109$(ASRC)/average-ps1-dev-2.$(ARCH).o \
     10$(ASRC)/average-ps1-v1.$(ARCH).o \
    1111$(ASRC)/secfilt.$(ARCH).o \
    1212$(ASRC)/secfilt-loneos.$(ARCH).o \
     
    1616$(ASRC)/secfilt-ps1-dev-1.$(ARCH).o \
    1717$(ASRC)/secfilt-ps1-dev-2.$(ARCH).o \
     18$(ASRC)/secfilt-ps1-v1.$(ARCH).o \
    1819$(ASRC)/measure.$(ARCH).o \
    1920$(ASRC)/measure-loneos.$(ARCH).o \
     
    2324$(ASRC)/measure-ps1-dev-1.$(ARCH).o \
    2425$(ASRC)/measure-ps1-dev-2.$(ARCH).o \
     26$(ASRC)/measure-ps1-v1.$(ARCH).o \
    2527$(ASRC)/missing.$(ARCH).o \
    2628$(ASRC)/photcode.$(ARCH).o \
     
    2931$(ASRC)/photcode-ps1-dev-2.$(ARCH).o \
    3032$(ASRC)/photcode-ps1-dev-3.$(ARCH).o \
     33$(ASRC)/photcode-ps1-v1.$(ARCH).o \
    3134$(ASRC)/image.$(ARCH).o \
    3235$(ASRC)/image-loneos.$(ARCH).o \
     
    3740$(ASRC)/image-ps1-dev-2.$(ARCH).o \
    3841$(ASRC)/image-ps1-dev-3.$(ARCH).o \
     42$(ASRC)/image-ps1-v1.$(ARCH).o \
    3943$(ASRC)/regimage.$(ARCH).o \
    4044$(ASRC)/detreg.$(ARCH).o \
    4145$(ASRC)/photreg.$(ARCH).o \
    4246$(ASRC)/photreg-old.$(ARCH).o \
    43 $(ASRC)/ps1_dev_0.$(ARCH).o \
    44 $(ASRC)/ps1_dev_1.$(ARCH).o \
    45 $(ASRC)/smpdata.$(ARCH).o \
     47$(ASRC)/cmf-ps1-dev-0.$(ARCH).o \
     48$(ASRC)/cmf-ps1-dev-1.$(ARCH).o \
     49$(ASRC)/cmf-ps1-v1.$(ARCH).o \
     50$(ASRC)/cmf-smpdata.$(ARCH).o \
    4651$(ASRC)/getstar-ps1-dev-0.$(ARCH).o \
    4752$(ASRC)/getstar-ps1-dev-1.$(ARCH).o \
     
    4954$(ASRC)/spectrum.$(ARCH).o \
    5055$(ASRC)/spectrum-ascii.$(ARCH).o \
    51 $(ASRC)/Stars.$(ARCH).o \
    5256$(ASRC)/GSCRegion.$(ARCH).o \
    5357$(ASRC)/AddstarClientOptions.$(ARCH).o \
     
    6367$(AINC)/average-ps1-dev-1.h \
    6468$(AINC)/average-ps1-dev-2.h \
     69$(AINC)/average-ps1-v1.h \
    6570$(AINC)/secfilt.h \
    6671$(AINC)/secfilt-loneos.h \
     
    7075$(AINC)/secfilt-ps1-dev-1.h \
    7176$(AINC)/secfilt-ps1-dev-2.h \
     77$(AINC)/secfilt-ps1-v1.h \
    7278$(AINC)/measure.h \
    7379$(AINC)/measure-loneos.h \
     
    7783$(AINC)/measure-ps1-dev-1.h \
    7884$(AINC)/measure-ps1-dev-2.h \
     85$(AINC)/measure-ps1-v1.h \
    7986$(AINC)/missing.h \
    8087$(AINC)/photcode.h \
     
    8390$(AINC)/photcode-ps1-dev-2.h \
    8491$(AINC)/photcode-ps1-dev-3.h \
     92$(AINC)/photcode-ps1-v1.h \
    8593$(AINC)/image.h \
    8694$(AINC)/image-loneos.h \
     
    9199$(AINC)/image-ps1-dev-2.h \
    92100$(AINC)/image-ps1-dev-3.h \
     101$(AINC)/image-ps1-v1.h \
    93102$(AINC)/regimage.h \
    94103$(AINC)/detreg.h \
    95104$(AINC)/photreg.h \
    96105$(AINC)/photreg-old.h \
    97 $(AINC)/ps1_dev_0.h \
    98 $(AINC)/ps1_dev_1.h \
     106$(AINC)/cmf-ps1-dev-0.h \
     107$(AINC)/cmf-ps1-dev-1.h \
     108$(AINC)/cmf-ps1-v1.h \
     109$(AINC)/cmf-smpdata.h \
    99110$(AINC)/getstar-ps1-dev-0.h \
    100111$(AINC)/getstar-ps1-dev-1.h \
    101112$(AINC)/getstar-ps1-dev-2.h \
    102 $(AINC)/smpdata.h \
    103113$(AINC)/spectrum.h \
    104114$(AINC)/spectrum-ascii.h \
    105 $(AINC)/Stars.h \
    106115$(AINC)/GSCRegion.h \
    107116$(AINC)/AddstarClientOptions.h \
    108117$(AINC)/SkyRegion.h
     118
     119# $(ASRC)/Stars.$(ARCH).o
     120# $(AINC)/Stars.h
     121
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/Stars.d

    r16810 r21536  
    22EXTNAME STARS
    33TYPE    BINTABLE
    4 SIZE    248
     4SIZE    278
    55
    6 FIELD     X,                X,          double,    x coordinate on image,            pixels
    7 FIELD     Y,                Y,          double,    y coordinate on image,            pixels
    8 FIELD     dX,               dX,         double,    x coordinate error,               pixels
    9 FIELD     dY,               dY,         double,    y coordinate error,               pixels
     6* FIELD     Xccd,             X,          double,    x coordinate on image,          pixels
     7* FIELD     Yccd,             Y,          double,    y coordinate on image,          pixels
     8* FIELD     dXccd,            dX,         double,    x coordinate error,                     pixels
     9* FIELD     dYccd,            dY,         double,    y coordinate error,             pixels
     10* FIELD     posangle,         POSANGLE,   float
     11* FIELD     pltscale,         PLTSCALE,   float
    1012FIELD     R,                R,          double,    ra coordinate on sky,             decimal degrees
    1113FIELD     D,                D,          double,    dec coordinate on sky,            decimal degrees
     
    1820FIELD     P,                PAR,        double,    parallax,                         milliarcsec
    1921FIELD     dP,               PAR_ERR,    double,    parallax error,                   milliarcsec
    20 FIELD     M,                M,          double,    instrumental mag
    21 FIELD     dM,               DM,         double,    error on mag
    22 FIELD     dMcal,            DMCAL,      double,    systematic error on mag
    23 FIELD     sky,              SKY,        double,    local sky counts
    24 FIELD     dsky,             dSKY,       double,    local sky error counts
    25 FIELD     fx,               FX,         double,    object FWHM x-dir,                pixels?
    26 FIELD     fy,               FY,         double,    object FWHM y-dir,                pixels?
    27 FIELD     df,               DF,         double,    object position angle,            degrees
    28 # FIELD     Mgal,             MGAL,       double,    alternative (galaxy) magnitude
    29 FIELD     Map,              MAP,        double,    alternative (aperture) magnitude
     22
     23* FIELD     M,                M,          double,    instrumental mag
     24* FIELD     dM,               DM,         double,    error on mag
     25* FIELD     dMcal,            DMCAL,      double,    systematic error on mag
     26* FIELD     Sky,              SKY,        double,    local sky counts
     27* FIELD     dSky,             dSKY,       double,    local sky error counts
     28* FIELD     fx,               FX,         double,    object FWHM x-dir,              pixels?
     29* FIELD     fy,               FY,         double,    object FWHM y-dir,              pixels?
     30* FIELD     df,               DF,         double,    object position angle,          degrees
     31* FIELD     Mcal,             MCAL,       float,     image cal magnitude
     32* FIELD     Map,              MAP,        double,    alternative (aperture) magnitude
    3033FIELD     Mpeak,            MPEAK,      double,    alternative (peak) magnitude
    31 FIELD     detID,            ID,         int,       detection identifier
    32 FIELD     imageID,          IMAGE_ID,   int,       image identifier
     34* FIELD     detID,            ID,         int,       detection identifier
     35* FIELD     imageID,          IMAGE_ID,   int,       image identifier
    3336FIELD     found,            FOUND,      int,       found in database catalog?
    34 FIELD     t,                T,          e_time,    date/time of exposure (UNIX)
    35 FIELD     dt,               EXPTIME,    float,     exposure time,                    2.5*log(exptime)
    36 FIELD     psfChisq,         PSF_CHISQ,  float
    37 FIELD     crNsigma,         CR_NSIGMA,  float
    38 FIELD     extNsigma,        EXT_NSIGMA, float
    39 FIELD     psfQual,          PSF_QUAL,   float
    40 FIELD     Mcal,             MCAL,       float,     image cal mag,                    mag
    41 FIELD     airmass,          AIRMASS,    float,     (airmass - 1),                    airmass
    42 FIELD     az,               AZ,         float,     azimuth
    43 FIELD     code,             CODE,       short
    44 FIELD     nFrames,          N_FRAMES,   short
    45 FIELD     flags,            FLAGS,      short
    46 FIELD     dophot,           DOPHOT,     char,      dophot type code
    47 FIELD     dummy,            DUMMY,      char
    48 
    49 # XXX I'm going to need azimuth (or load from image header?)
     37* FIELD     t,                T,          e_time,    date/time of exposure (UNIX)
     38* FIELD     t_msec,           T_MSEC,     short,     milliseconds of exposure
     39* FIELD     dt,               EXPTIME,    float,     exposure time,                    2.5*log(exptime)
     40* FIELD     psfQual,          PSF_QUAL,   float
     41* FIELD     psfChisq,         PSF_CHISQ,  float
     42* FIELD     psfNdof,          PSF_NDOF,   int
     43* FIELD     psfNpix,          PSF_NPIX,   int
     44* FIELD     crNsigma,         CR_NSIGMA,  float
     45* FIELD     extNsigma,        EXT_NSIGMA, float
     46* FIELD     Mxx,              MOMENTS_XX, float,     second moment
     47* FIELD     Mxy,              MOMENTS_XY, float,     second moment
     48* FIELD     Myy,              MOMENTS_YY, float,     second moment
     49* FIELD     airmass,          AIRMASS,    float,     (airmass - 1),                  airmass
     50* FIELD     az,             AZ,         float,     azimuth
     51* FIELD     photcode,         CODE,       short
     52* FIELD     nFrames,          N_FRAMES,   short
     53* FIELD     photFlags,        FLAGS,      short
     54FIELD     dummy,            DUMMY,      char[2]
    5055
    5156# double:   24 * 8 : 192
     
    5863# define down the types to floats where reasonable (all but R,D)?
    5964# R,D should be in ICRS, J2000, epoch 2000 : precess as needed, apply p-m as needed
     65
     66# XXX I'd like to merge this with Measure, but need to be careful about addstarClient -> addstarServer
     67# XXX extend photFlags to match actual psphot output
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/average.d

    r16810 r21536  
    22EXTNAME      DVO_AVERAGE
    33TYPE         BINTABLE
    4 SIZE         80
     4SIZE         94
    55DESCRIPTION  DVO Average Object Table
    66
    77# elements of data structure / FITS table
    88
    9 FIELD R,              RA,         double,           RA,                           decimal degrees
    10 FIELD D,              DEC,        double,           DEC,                          decimal degrees
    11 FIELD dR,             RA_ERR,     float,            RA error                      arcsec
    12 FIELD dD,             DEC_ERR,    float,            DEC error                     arcsec
     9FIELD R,              RA,          double,          RA,                           decimal degrees
     10FIELD D,              DEC,         double,          DEC,                          decimal degrees
     11FIELD dR,             RA_ERR,      float,           RA error                      arcsec
     12FIELD dD,             DEC_ERR,     float,           DEC error                     arcsec
     13                                   
     14FIELD uR,             U_RA,        float,           RA*cos(D) proper-motion,      arcsec/year
     15FIELD uD,             U_DEC,       float,           DEC proper-motion,            arcsec/year
     16FIELD duR,            V_RA_ERR,    float,           RA*cos(D) p-m error,          arcsec/year
     17FIELD duD,            V_DEC_ERR,   float,           DEC p-m error,                arcsec/year
     18FIELD P,              PAR,         float,           parallax,                     arcsec
     19FIELD dP,             PAR_ERR,     float,           parallax error,               arcsec
    1320
    14 FIELD uR,             U_RA,       float,            RA*cos(D) proper-motion,      arcsec/year
    15 FIELD uD,             U_DEC,      float,            DEC proper-motion,            arcsec/year
    16 FIELD duR,            V_RA_ERR,   float,            RA*cos(D) p-m error,          arcsec/year
    17 FIELD duD,            V_DEC_ERR,  float,            DEC p-m error,                arcsec/year
    18 FIELD P,              PAR,        float,            parallax,                     arcsec
    19 FIELD dP,             PAR_ERR,    float,            parallax error,               arcsec
     21FIELD Xp,             SIGMA_POS,   short,           position scatter,             1/100 arcsec
     22FIELD ChiSq,          CHISQ_POS,   float,           astrometry analysis chisq
     23FIELD Npos,           NUMBER_POS,  unsigned short,  number of detections used for astrometry
    2024
    21 FIELD Xp,             SIGMA_POS,   short,           position scatter,             1/100 arcsec
     25# this limits us to a max of 64k measurements per object
    2226FIELD Nmeasure,       NMEASURE,    unsigned short,  number of psf measurements
    2327FIELD Nmissing,       NMISSING,    unsigned short,  number of missings
    2428FIELD Nextend,        NEXTEND,     unsigned short,  number of extended measurements
    25 FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
    26 FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
    27 FIELD extendOffset,   OFF_EXTEND,  int,             offset to first extended measurement
    2829
    29 FIELD code,           code,       unsigned short,   ID code (star; ghost; etc)
    30 FIELD dummy,          DUMMY,      char[2],          padding
     30FIELD measureOffset,  OFF_MEASURE, int,             offset to first psf measurement
     31FIELD missingOffset,  OFF_MISSING, int,             offset to first missing obs
     32FIELD extendOffset,   OFF_EXTEND,  int,             offset to first extended measurement
    3133
    32 # Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints
    33 # for C89 compatibility.  The objID is constructed based on the
    34 # position of first instatiation.  this is actually quite expensive
    35 # because we need to include the uniqueness test to construct this,
    36 # which requires a select for each new object.  Therefore, I will use
    37 # a table based ID (table ID + object ID), and we will have to
    38 # re-number the object IDs if we change the table density, OR treat
    39 # all subdivisions as entries which are from a foreign table.
     34# 'flags' was called 'code' prior to 2009.02.07
     35FIELD flags,          FLAGS,       uint32_t,        average object flags (star; ghost; etc)
    4036
    41 FIELD objID,          OBJ_ID,    unsigned int,   unique ID for object in table
    42 FIELD catID,          CAT_ID,    unsigned int,   unique ID for table in which object was first realized
     37# objID + catID gives a unique ID for all objects in the database
     38FIELD objID,          OBJ_ID,      unsigned int,    unique ID for object in table
     39FIELD catID,          CAT_ID,      unsigned int,    unique ID for table in which object was first realized
     40FIELD extID,          EXT_ID,      uint64_t,        external ID for object (eg PSPS objID)
    4341
    4442# this structure should only be used for internal representations
     
    4745# the index for the secfilt table is just Nsecfilt times the index for the average table.
    4846
    49 # the DVO object IDs are generated internally and are not equivalent to the PSPS object IDs
    50 # probably need to add position chisq
    51 
    52 # XXX include the number of measurements used to determine the positional information?
     47# *** 20090206 : new fields : ChiSq, Npos, flags (was code, uint16_t), extID
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/image.d

    r20936 r21536  
    4040# 40 bytes
    4141
    42 FIELD     name,             NAME,                 char[128],      name of original image
     42FIELD     name,             NAME,                 char[121],      name of original image
    4343FIELD     detection_limit,  DETECTION_LIMIT,      unsigned char,  detection limit,           10*mag
    4444FIELD     saturation_limit, SATURATION_LIMIT,     unsigned char,  saturation limit,          10*mag
     
    4747FIELD     fwhm_y,           FWHM_Y,               unsigned char,  PSF y width,               25*arcsec
    4848FIELD     trate,            TRATE,                unsigned char,  scan rate,                 100 usec/pixel
    49 FIELD     code,             CODE,                 char,           image quality flag
    5049FIELD     ccdnum,           CCDNUM,               unsigned char,  CCD ID number
     50FIELD     flags,            FLAGS,                unsigned int,   image quality flags
    5151FIELD     imageID,          IMAGE_ID,             unsigned int,   internal image ID
    52 
    53 # XXX do we want to use this to handle mosaics?
    54 # FIELD           parentID,         PARENT_ID,            unsigned int,   associated ref image
     52FIELD     parentID,         PARENT_ID,            unsigned int,   associated ref image
    5553FIELD     externID,         EXTERN_ID,            unsigned int,   external image ID
    5654FIELD     sourceID,         SOURCE_ID,            unsigned short, analysis source ID
     
    7371FIELD     Myyyy,            MYYYY,                short,          Mrel polyterm
    7472# 40 bytes
     73
     74# *** 20090206 : new fields : parentID, flags (was code char), changed name to 121 bytes.
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/measure-panstarrs-dev-0.d

    r15511 r21536  
    4646
    4747# do we need more resolution than a short? should this be a log?
    48 FIELD qPSF,           PSF_QF,       short,          psf coverage/quality factor
     48FIELD psfQual,        PSF_QF,       short,          psf coverage/quality factor
    4949
    5050FIELD dophot,         DOPHOT,       char,           dophot type
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/measure-panstarrs-dev-1.d

    r15511 r21536  
    4646
    4747# do we need more resolution than a short? should this be a log?
    48 FIELD qPSF,           PSF_QF,       short,          psf coverage/quality factor
     48FIELD psfQual,        PSF_QF,       short,          psf coverage/quality factor
    4949
    5050FIELD dophot,         DOPHOT,       char,           dophot type
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/measure-ps1-dev-1.d

    r16810 r21536  
    3333
    3434# do we need more resolution than a short? should this be a log?
    35 FIELD qPSF,           PSF_QF,       float,          psf coverage/quality factor
     35FIELD psfQual,        PSF_QF,       float,          psf coverage/quality factor
    3636FIELD psfChisq,       PSF_CHISQ,    float,          psf coverage/quality factor
    3737FIELD crNsigma,       CR_NSIGMA,    float,          psf coverage/quality factor
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/measure-ps1-dev-2.d

    r16810 r21536  
    3434
    3535# do we need more resolution than a short? should this be a log?
    36 FIELD qPSF,           PSF_QF,       float,          psf coverage/quality factor
     36FIELD psfQual,        PSF_QF,       float,          psf coverage/quality factor
    3737FIELD psfChisq,       PSF_CHISQ,    float,          psf fit chisq
    3838FIELD crNsigma,       CR_NSIGMA,    float,          Nsigma deviation towards CR
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/measure.d

    r16810 r21536  
    22EXTNAME      DVO_MEASURE
    33TYPE         BINTABLE
    4 SIZE         112
     4SIZE         146
    55DESCRIPTION  DVO Detection Measurement Table
    66
    7 FIELD dR,             D_RA,         float,          RA offset,                    arcsec
    8 FIELD dD,             D_DEC,        float,          DEC offset,                   arcsec
    9 FIELD M,              MAG,          float,          catalog mag,                  mag
    10 FIELD Mcal,           M_CAL,        float,          image cal mag,                mag
    11 FIELD Map,            M_APER,       float,          aperture mag,                 mag
    12 FIELD dM,             MAG_ERR,      float,          mag error,                    mag
    13 FIELD dMcal,          MAG_CAL_ERR,  float,          systematic calibration error, mag
    14 FIELD dt,             M_TIME,       float,          exposure time,                2.5*log(exptime)
     7FIELD dR,             D_RA,         float,          RA offset,                      arcsec
     8FIELD dD,             D_DEC,        float,          DEC offset,                     arcsec
     9FIELD M,              MAG,          float,          catalog mag,                    mag
     10FIELD Mcal,           M_CAL,        float,          image cal mag,                  mag
     11FIELD Map,            M_APER,       float,          aperture mag,                   mag
     12FIELD dM,             MAG_ERR,      float,          mag error,                      mag
     13FIELD dMcal,          MAG_CAL_ERR,  float,          systematic calibration error,   mag
     14FIELD dt,             M_TIME,       float,          exposure time,                  2.5*log(exptime)
    1515
    1616# note that with airmass = 1.0 / cos(90 - alt), we have full alt/az representation
    17 FIELD airmass,        AIRMASS,      float,          (airmass - 1),                airmass
     17FIELD airmass,        AIRMASS,      float,          (airmass - 1),                  airmass
    1818FIELD az,             AZ,           float,          telescope azimuth
    1919
    2020# new field elements needed for Pan-STARRS:
    21 FIELD Xccd,           X_CCD,        float,          X coord on chip,               pixels
    22 FIELD Yccd,           Y_CCD,        float,          Y coord on chip,               pixels
     21FIELD Xccd,           X_CCD,        float,          X coord on chip,                pixels
     22FIELD Yccd,           Y_CCD,        float,          Y coord on chip,                pixels
    2323
    2424# could these be packed into fewer bits?
    25 FIELD Sky,            SKY_FLUX,     float,          local estimate of sky flux,    counts/sec
    26 FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,    counts/sec
     25FIELD Sky,            SKY_FLUX,     float,          local estimate of sky flux,     counts/sec
     26FIELD dSky,           SKY_FLUX_ERR, float,          local estimate of sky flux,     counts/sec
    2727
    28 FIELD t,              TIME,         unsigned int,   time in seconds (UNIX)
     28FIELD t,              TIME,         int,            time in seconds (UNIX)
     29FIELD t_msec,         TIME_MSEC,    unsigned short, time fraction of second,        milliseconds
    2930FIELD averef,         AVE_REF,      unsigned int,   reference to average entry     
    3031
    31 # Pan-STARRS uses a 64-bit detection ID.  keep this in two 32 bit ints for backwards compatibility?
    3232FIELD detID,          DET_ID,       unsigned int,   detection ID
    3333FIELD imageID,        IMAGE_ID,     unsigned int,   reference to DVO image ID
     34FIELD objID,          OBJ_ID,       unsigned int,   unique ID for object in table
     35FIELD catID,          CAT_ID,       unsigned int,   unique ID for table in which object was first realized
     36
     37# PSPS uses a 64-bit detection ID
     38FIELD extID,          EXT_ID,       uint64_t,       external ID (eg PSPS detID)
    3439
    3540# do we need more resolution than a short? should this be a log?
    36 FIELD qPSF,           PSF_QF,       float,          psf coverage/quality factor
     41FIELD psfQual,        PSF_QF,       float,          psf coverage/quality factor
    3742FIELD psfChisq,       PSF_CHISQ,    float,          psf fit chisq
     43FIELD psfNdof,        PSF_NDOF,     int,            psf degrees of freedom
     44FIELD psfNpix,        PSF_NPIX,     int,            psf number of pixels
    3845FIELD crNsigma,       CR_NSIGMA,    float,          Nsigma deviation towards CR
    3946FIELD extNsigma,      EXT_NSIGMA,   float,          Nsigma deviation towards EXT
    4047
    41 FIELD FWx,            FWHM_MAJOR,   short,          object fwhm major axis,       1/100 of arcsec
    42 FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,       1/100 of arcsec
    43 FIELD theta,          PSF_THETA,    short,          angle wrt ccd X dir,          (0xffff/360) deg
     48# model shape parameters
     49FIELD FWx,            FWHM_MAJOR,   short,          object fwhm major axis,         1/100 of pixels
     50FIELD FWy,            FWHM_MINOR,   short,          object fwhm minor axis,         1/100 of pixels
     51FIELD theta,          PSF_THETA,    short,          angle wrt ccd X dir,            (0xffff/360) deg
     52
     53# moments
     54FIELD Mxx,            MXX,          short,          second moments in pixel coords, 1/100 of pixels^2
     55FIELD Mxy,            MXY,          short,          second moments in pixel coords, 1/100 of pixels^2
     56FIELD Myy,            MYY,          short,          second moments in pixel coords, 1/100 of pixels^2
     57
     58# convert this to error in pixels on load?
     59FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,          1/100 of pixels
     60FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,          1/100 of pixels
     61
     62FIELD posangle,       POSANGLE,     short,          position angle sky to chip,     (0xffff/360) deg
     63FIELD pltscale,       PLTSCALE,     float,          plate scale,                    arcsec/pixel
     64
    4465FIELD photcode,       PHOTCODE,     unsigned short, photcode
     66FIELD dbFlags,        DB_FLAGS,     unsigned int,   flags supplied by analysis in database
     67FIELD photFlags,      PHOT_FLAGS,   unsigned int,   flags supplied by photometry program
    4568
    46 # convert this to error in arcsec on load?
    47 FIELD dXccd,          X_CCD_ERR,    short,          X coord error on chip,         pixels
    48 FIELD dYccd,          Y_CCD_ERR,    short,          Y coord error on chip,         pixels
     69# *** 20090206 : new fields : t_msec, extID, Mxx, Mxy, Myy, posangle,
     70#                psfNdof, psfNpix, Map_small; deprecated dophot.
     71#                Changed dbFlags, photFlags : uint16_t to uint64_t
    4972
    50 FIELD dbFlags,        DB_FLAGS,     unsigned short, flags for various uses 
    51 FIELD photFlags,      PHOT_FLAGS,   unsigned short, flags supplied by photometry program
    52 
    53 FIELD stargal,        STAR_GAL,     char,           star-galaxy separator
    54 
    55 # absorb these into photFlags?
    56 FIELD dophot,         DOPHOT,       char,           dophot type
    57 
    58 FIELD dummy,          DUMMY,        char[6],        padding
     73# XXX unsigned int values are probably not being saved in the FITS file correctly: no BZERO, BSCALE
  • branches/cnb_branch_20090215/Ohana/src/libautocode/def/secfilt.d

    r12332 r21536  
    22EXTNAME      DVO_SECFILT
    33TYPE         BINTABLE
    4 SIZE         16
     4SIZE         18
    55DESCRIPTION  DVO SecFilt : Secondary Filter Data
    66
     
    1111FIELD  Ncode, NCODE,    short,                number of detections in band
    1212FIELD  Nused, NUSED,    short,                number of detections used in average
    13 FIELD  dummy, JUNK,     short,                place holder
     13FIELD  M_20,  MAG_20,   short,                lower 20percent mag,      millimags
     14FIELD  M_80,  MAG_80,   short,                upper 20percent mag,      millimags
     15
     16# *** 20090206 : new fields : M_20, M_80; dropped dummy
  • branches/cnb_branch_20090215/Ohana/src/libautocode/doc/autocode.txt

    r3515 r21536  
     1
     22009.02.07
     3
     4The autocode tables currently use type names which are ambiguous in
     5terms of their actual sizes in bits.  I've added the intNN_t and
     6uintNN_t types -- this requires --use-gnu99 with configure
     7
     8see libdvo/doc/notes.txt for instructions on adding new dvo catalog formats
     9
     102007.00.00
    111
    212This directory contains a collection of autocoded FITS I/O routines
  • branches/cnb_branch_20090215/Ohana/src/libautocode/generate

    r7080 r21536  
    114114       
    115115        # rawshort is a short without byteswapping
     116        # rawshort is a patch for old photreg tables
    116117
    117118        $pt1 = 0;
     
    124125        if ($type eq "int")           { $pt1 = "J"; }
    125126        if ($type eq "unsigned int")  { $pt1 = "J"; }
    126         if ($type eq "e_time")        { $pt1 = "J"; }
     127
     128        if ($type eq "int8_t")        { $pt1 = "B"; }
     129        if ($type eq "uint8_t")       { $pt1 = "B"; }
     130        if ($type eq "int16_t")       { $pt1 = "I"; }
     131        if ($type eq "uint16_t")      { $pt1 = "I"; }
     132        if ($type eq "int32_t")       { $pt1 = "J"; }
     133        if ($type eq "uint32_t")      { $pt1 = "J"; }
     134
     135        # FITS tables do not allow for 64bit integers.  we need to
     136        # write these by splitting the value into high and low 32 bit values
     137        if ($type eq "int64_t")       { $pt1 = "J"; $Np = 2*$Np; }
     138        if ($type eq "uint64_t")      { $pt1 = "J"; $Np = 2*$Np; }
     139
    127140        if ($type eq "float")         { $pt1 = "E"; }
    128141        if ($type eq "double")        { $pt1 = "D"; }
    129142
     143        # special 'elixir' types:
     144        if ($type eq "e_time")        { $pt1 = "J"; }
    130145        if ($type eq "e_void")        { $pt1 = "B"; $Np = 8*$Np; }
    131146        # e_void is a 64 bit pointer, cast to size_t.  its value is not loaded
     
    146161        printf FILE "%-20s 1.0, 0.0);\n", "\"$unit[$i]\", ";
    147162    }
    148 
    149163}
    150164
     
    217231        if ($type eq "int")           { $pt1 = sprintf "I%s", $length; }
    218232        if ($type eq "unsigned int")  { $pt1 = sprintf "I%s", $length; }
    219         if ($type eq "e_time")        { $pt1 = sprintf "I%s", $length; }
     233
     234        if ($type eq "int8_t")        { $pt1 = sprintf "I%s", $length; }
     235        if ($type eq "uint8_t")       { $pt1 = sprintf "I%s", $length; }
     236        if ($type eq "int16_t")       { $pt1 = sprintf "I%s", $length; }
     237        if ($type eq "uint16_t")      { $pt1 = sprintf "I%s", $length; }
     238        if ($type eq "int32_t")       { $pt1 = sprintf "I%s", $length; }
     239        if ($type eq "uint32_t")      { $pt1 = sprintf "I%s", $length; }
     240
     241        # FITS tables do not allow for 64bit integers.  we need to
     242        # write these by splitting the value into high and low 32 bit values
     243        if ($type eq "int64_t")       { $pt1 = sprintf "I%s", $length; }
     244        if ($type eq "uint64_t")      { $pt1 = sprintf "I%s", $length; }
     245
    220246        if ($type eq "float")         { $pt1 = sprintf "F%s", $length; }
    221247        if ($type eq "double")        { $pt1 = sprintf "F%s", $length; }
    222248
     249        # special 'elixir' types:
     250        if ($type eq "e_time")        { $pt1 = sprintf "I%s", $length; }
    223251        if ($type eq "e_void")        { $pt1 = sprintf "I%s", $length; }
    224252
     
    283311        if ($type eq "unsigned char") { $N +=   $Np; next; }
    284312        if ($type eq "rawshort")      { $N += 2*$Np; next; }
     313
    285314        if ($type eq "short")         { $T = "BYTE"; $n = 2; }
    286315        if ($type eq "unsigned short"){ $T = "BYTE"; $n = 2; }
    287316        if ($type eq "int")           { $T = "WORD"; $n = 4; }
    288317        if ($type eq "unsigned int")  { $T = "WORD"; $n = 4; }
     318
     319        if ($type eq "int8_t")        { $N +=   $Np; next; }
     320        if ($type eq "uint8_t")       { $N +=   $Np; next; }
     321        if ($type eq "int16_t")       { $T = "BYTE"; $n = 2; }
     322        if ($type eq "uint16_t")      { $T = "BYTE"; $n = 2; }
     323        if ($type eq "int32_t")       { $T = "WORD"; $n = 4; }
     324        if ($type eq "uint32_t")      { $T = "WORD"; $n = 4; }
     325
     326        # FITS tables do not allow for 64bit integers.  we need to
     327        # write these by splitting the value into high and low 32 bit values
     328        if ($type eq "int64_t")       { $T = "WORD"; $n = 4; $Np = 2*$Np; }
     329        if ($type eq "uint64_t")      { $T = "WORD"; $n = 4; $Np = 2*$Np; }
     330
     331        if ($type eq "float")         { $T = "WORD"; $n = 4; }
     332        if ($type eq "double")        { $T = "DBLE"; $n = 8; }
     333
     334        # special 'elixir' types:
    289335        if ($type eq "e_time")        { $T = "WORD"; $n = 4; }
    290336        if ($type eq "e_void")        { $T = "DBLE"; $n = 8; }
    291         if ($type eq "float")         { $T = "WORD"; $n = 4; }
    292         if ($type eq "double")        { $T = "DBLE"; $n = 8; }
     337
    293338        if (!$n) { die "unknown type $type"; }
    294339        for ($j = 0; $j < $Np; $j++) {
     
    318363        if ($type eq "int")            { $Nbytes += 4*$Np; $valid = 1; }
    319364        if ($type eq "unsigned int")   { $Nbytes += 4*$Np; $valid = 1; }
     365
     366        if ($type eq "int8_t")         { $Nbytes += 1*$Np; $valid = 1; }
     367        if ($type eq "uint8_t")        { $Nbytes += 1*$Np; $valid = 1; }
     368        if ($type eq "int16_t")        { $Nbytes += 2*$Np; $valid = 1; }
     369        if ($type eq "uint16_t")       { $Nbytes += 2*$Np; $valid = 1; }
     370        if ($type eq "int32_t")        { $Nbytes += 4*$Np; $valid = 1; }
     371        if ($type eq "uint32_t")       { $Nbytes += 4*$Np; $valid = 1; }
     372
     373        # FITS tables do not allow for 64bit integers.  we need to
     374        # write these by splitting the value into high and low 32 bit values
     375        if ($type eq "int64_t")        { $Nbytes += 8*$Np; $valid = 1; }
     376        if ($type eq "uint64_t")       { $Nbytes += 8*$Np; $valid = 1; }
     377
     378        if ($type eq "float")          { $Nbytes += 4*$Np; $valid = 1; }
     379        if ($type eq "double")         { $Nbytes += 8*$Np; $valid = 1; }
     380
     381        # special 'elixir' types:
    320382        if ($type eq "e_time")         { $Nbytes += 4*$Np; $valid = 1; }
    321383        if ($type eq "e_void")         { $Nbytes += 8*$Np; $valid = 1; }
    322         if ($type eq "float")          { $Nbytes += 4*$Np; $valid = 1; }
    323         if ($type eq "double")         { $Nbytes += 8*$Np; $valid = 1; }
    324384        if (!$valid) { die "unknown type $type"; }
    325385    }
  • branches/cnb_branch_20090215/Ohana/src/libdvo/Makefile

    r17419 r21536  
    3131$(DESTINC)/ps1_dev_1_defs.h \
    3232$(DESTINC)/ps1_dev_2_defs.h \
    33 $(DESTINC)/ps1_dev_3_defs.h
     33$(DESTINC)/ps1_dev_3_defs.h \
     34$(DESTINC)/ps1_v1_defs.h
    3435
    3536INCS = $(DEFS) $(DESTINC)/dvo.h $(DESTINC)/autocode.h
     
    6566$(SRC)/dvo_convert_PS1_DEV_2.$(ARCH).o \
    6667$(SRC)/dvo_convert_PS1_DEV_3.$(ARCH).o \
     68$(SRC)/dvo_convert_PS1_V1.$(ARCH).o \
    6769$(SRC)/skyregion_io.$(ARCH).o    \
    6870$(SRC)/skyregion_gsc.$(ARCH).o    \
  • branches/cnb_branch_20090215/Ohana/src/libdvo/doc/notes.txt

    r12332 r21536  
    22Adding a new dvo catalog format.  Assume the new format name is 'foo'.
    33
    4 1) create the autocode definition files for average, measure, secfilt, image
    5    these files must be a subset of the internal versions of these same
    6    tables.  if you intend to add fields which don't exist in the
    7    internal tables, you must update the internal tables as well.  the
    8    naming convention is: average-foo.d, etc.
     41) create the autocode definition files for average, measure, secfilt,
     5   image, and photcode.  these files must be a subset of the internal
     6   versions of these same tables.  if you intend to add fields which
     7   don't exist in the internal tables, you must update the internal
     8   tables as well.  the naming convention is: average-foo.d, etc.
    99
    10102) add the new definition files to libautocode/Makefile.Targets (both
     
    2222 (libdvo/src/dvo_catalog.c).  The name should be "FOO".
    2323
    24 6) add entry for structure size in dvo_catalog_load_raw
    25    (libdvo/src/dvo_catalog_raw.c), since this is not available from
    26    the header.
     246) in libdvo/src/dvo_catalog_raw.c, update the FORMAT_CASE lists to
     25   include the new STRUCT name.
    2726
    28 7) add entries in ReadRawAverage, WriteRawAverage, ReadRawMeasure,
    29    WriteRawMeasure, ReadRawSecFilt, WriteRawSecFilt.  Make sure to use
    30    the new STRUCT names. the conversion function gfit_convert_Foo will
    31    be automatically generated.
     277) create a new conversion file dvo_convert_foo.c and define the
     28   internal to Foo conversions.
    3229
    33 8) add entry in WriteRawAverage, making sure to use the new STRUCT
    34    name. the conversion function gfit_convert_Foo will be
    35    automatically generated. 
     308) add the new format to the list of FORMAT conversion in dvo_convert.c.
    3631
    37 9) create a new conversion file dvo_convert_foo.c and define the
    38    internal to Foo conversions.
     329) any changes to the internal format need to be reflected in the
     33   functions in the dvo_convert_*.c files.  These files are defined so
     34   that changed fields are sequential in the functions.  This should
     35   make is easy to identify the new changes needed.
     36
     3710) add the new format to the section at the end of dvo_image.c
     38
     3911) add the new format to the dvo_image_raw.c
     40
     4112) add the photcode format conversions to libdvo/src/LoadPhotcodesFITS.c
     42
     4312) switch the output photcode format conversion ina libdvo/src/SavePhotcodesFITS.c
     44
     4513) Add the conversion functions to the header file libdvo/include/foo_defs.h
    3946
    4047* Note some esoteric format issues: 
     
    5461    keywords.
    5562
     63----
     64
     6520090207 : adding PS1_V1
     66
     67measure:
     68 new fields : t_msec, extID, Mxx, Mxy, Myy, dTccd; deprecated dophot
     69 dbFlags, photFlags : uint16_t to uint64_t
     70
     71average:
     72 new fields : ChiSq, Npos, flags (was code, uint16_t), extID
     73
     74secfilt:
     75 new fields : M_20, M_80; dropped dummy
     76
     77image:
     78 new fields : parentID, flags (was code char), changed name to 121 bytes.
     79
     80photcode:
     81 new fields : NONE
     82
     83** parentID was added to enable easy lookups from chip->fpa for mosaic
     84   astrometry.  In old databases, this conversion was done by making
     85   the match via the time and photcode.  This conversion needs to be
     86   done on load...
  • branches/cnb_branch_20090215/Ohana/src/libdvo/include/dvo.h

    r21153 r21536  
    1818              DVO_FORMAT_PS1_DEV_1,
    1919              DVO_FORMAT_PS1_DEV_2,
    20               DVO_FORMAT_PS1_DEV_3
     20              DVO_FORMAT_PS1_DEV_3,
     21              DVO_FORMAT_PS1_V1
    2122} DVOTableFormat;
    2223
     
    407408# include "ps1_dev_2_defs.h"
    408409# include "ps1_dev_3_defs.h"
     410# include "ps1_v1_defs.h"
    409411
    410412/*** DVO image db I/O Functions ***/
     
    444446void sort_image_subset (Image *image, int *subset, int N);
    445447void sort_coords_index (double *X, double *Y, int *S, int N);
    446 void sort_stars_ra (Stars *stars, int N);
    447448void sort_regions (SkyRegion *region, int N);
    448449
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/LoadPhotcodesFITS.c

    r17190 r21536  
    4040  gfits_scan (&db.theader, "EXTNAME", "%s", 1, extname);
    4141
    42   if (!strcmp (extname, "DVO_PHOTCODE") || !strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
     42  if (!strcmp (extname, "DVO_PHOTCODE")) {
     43    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
     44    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
     45    free (photcode_elixir);
     46  }
     47
     48  if (!strcmp (extname, "DVO_PHOTCODE_ELIXIR")) {
    4349    PhotCode_Elixir *photcode_elixir = gfits_table_get_PhotCode_Elixir (&db.ftable, &Ncode, &db.swapped);
    4450    photcode = PhotCode_Elixir_To_Internal (photcode_elixir, Ncode);
     
    6268    photcode = PhotCode_PS1_DEV_3_To_Internal (photcode_ps1_dev_3, Ncode);
    6369    free (photcode_ps1_dev_3);
     70  }
     71
     72  if (!strcmp (extname, "DVO_PHOTCODE_PS1_V1")) {
     73    PhotCode_PS1_V1 *photcode_ps1_v1 = gfits_table_get_PhotCode_PS1_V1 (&db.ftable, &Ncode, &db.swapped);
     74    photcode = PhotCode_PS1_V1_To_Internal (photcode_ps1_v1, Ncode);
     75    free (photcode_ps1_v1);
    6476  }
    6577
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/SavePhotcodesFITS.c

    r17190 r21536  
    2929  // for the moment, we simply support the latest photcode format for output
    3030  // XXX update this as needed as new formats are defined
    31   PhotCode_PS1_DEV_3 *photcode_output = PhotCode_Internal_To_PS1_DEV_3 (table[0].code, table[0].Ncode);
     31  PhotCode_PS1_V1 *photcode_output = PhotCode_Internal_To_PS1_V1 (table[0].code, table[0].Ncode);
    3232
    3333  /* convert FITS format data to internal format (byteswaps & EXTNAME) */
    3434  gfits_db_create (&db);
    35   gfits_table_set_PhotCode_PS1_DEV_3 (&db.ftable, photcode_output, table[0].Ncode);
     35  gfits_table_set_PhotCode_PS1_V1 (&db.ftable, photcode_output, table[0].Ncode);
    3636  gfits_db_save (&db);
    3737  gfits_db_close (&db);
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_catalog.c

    r20981 r21536  
    5252  if (!strcasecmp (catformat, "PS1_DEV_1"))       return (DVO_FORMAT_PS1_DEV_1);
    5353  if (!strcasecmp (catformat, "PS1_DEV_2"))       return (DVO_FORMAT_PS1_DEV_2);
     54  if (!strcasecmp (catformat, "PS1_V1"))          return (DVO_FORMAT_PS1_V1);
    5455  return (DVO_FORMAT_UNDEF);
    5556}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_catalog_raw.c

    r20982 r21536  
    8686      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    8787      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     88      FORMAT_CASE (PS1_V1,    PS1_V1);
    8889
    8990    default:
     
    271272  if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_1)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_1");
    272273  if (catalog[0].catformat == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
     274  if (catalog[0].catformat == DVO_FORMAT_PS1_V1)          gfits_modify (&catalog[0].header, "FORMAT", "%s", 1, "PS1_V1");
    273275
    274276  /* rewind file pointers and truncate file */
     
    366368      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    367369      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     370      FORMAT_CASE (PS1_V1,    PS1_V1);
    368371
    369372    default:
     
    412415      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    413416      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     417      FORMAT_CASE (PS1_V1,    PS1_V1);
    414418
    415419    default:
     
    462466      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    463467      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     468      FORMAT_CASE (PS1_V1,    PS1_V1);
    464469
    465470    default:
     
    508513      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    509514      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     515      FORMAT_CASE (PS1_V1,    PS1_V1);
    510516
    511517    default:
     
    558564      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    559565      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     566      FORMAT_CASE (PS1_V1,    PS1_V1);
    560567
    561568    default:
     
    604611      FORMAT_CASE (PS1_DEV_1, PS1_DEV_1);
    605612      FORMAT_CASE (PS1_DEV_2, PS1_DEV_2);
     613      FORMAT_CASE (PS1_V1,    PS1_V1);
    606614
    607615    default:
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert.c

    r19185 r21536  
    4949  CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    5050  CONVERT_FORMAT ("DVO_AVERAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     51  CONVERT_FORMAT ("DVO_AVERAGE_PS1_V1",          PS1_V1,          PS1_V1);
    5152# undef CONVERT_FORMAT
    5253
     
    7980      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    8081      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     82      FORMAT_CASE (PS1_V1,          PS1_V1);
    8183# undef FORMAT_CASE
    8284
     
    122124  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    123125  CONVERT_FORMAT ("DVO_MEASURE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     126  CONVERT_FORMAT ("DVO_MEASURE_PS1_V1",          PS1_V1,          PS1_V1);
    124127# undef CONVERT_FORMAT
    125128
     
    152155      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    153156      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     157      FORMAT_CASE (PS1_V1,          PS1_V1);
    154158# undef FORMAT_CASE
    155159
     
    195199  CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    196200  CONVERT_FORMAT ("DVO_SECFILT_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
     201  CONVERT_FORMAT ("DVO_SECFILT_PS1_V1",          PS1_V1,          PS1_V1);
    197202# undef CONVERT_FORMAT
    198203
     
    225230      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    226231      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
     232      FORMAT_CASE (PS1_V1,          PS1_V1);
    227233# undef FORMAT_CASE
    228234
     
    288294  CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_1",       PS1_DEV_1,       PS1_DEV_1);
    289295  CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_2",       PS1_DEV_2,       PS1_DEV_2);
    290   CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
     296  CONVERT_FORMAT ("DVO_IMAGE_PS1_V1",          PS1_V1,          PS1_V1);
     297
     298  // XXX Not sure this was ever actually used -- it was not complete...
     299  // CONVERT_FORMAT ("DVO_IMAGE_PS1_DEV_3",       PS1_DEV_3,       PS1_DEV_3);
     300
    291301# undef CONVERT_FORMAT
    292302
     
    322332      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    323333      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    324       FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
     334      FORMAT_CASE (PS1_V1,          PS1_V1);
     335
     336      // XXX not sure this was actually used: it was incomplete
     337      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
    325338# undef FORMAT_CASE
    326339
     
    372385      FORMAT_CASE (PS1_DEV_1,       PS1_DEV_1);
    373386      FORMAT_CASE (PS1_DEV_2,       PS1_DEV_2);
    374       FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
     387      FORMAT_CASE (PS1_V1,          PS1_V1);
     388
     389      // XXX not sure this was used, it was incomplete
     390      // FORMAT_CASE (PS1_DEV_3,       PS1_DEV_3);
     391
    375392# undef FORMAT_CASE
    376393
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_1.c

    r19185 r21536  
    1515    out[i].M          = in[i].M;
    1616    out[i].Mcal       = in[i].Mcal;
    17     out[i].Map        = in[i].Mgal;
    1817    out[i].dM         = in[i].dM;
    1918    out[i].dt         = in[i].dt;
     
    2827    out[i].detID      = in[i].detID;
    2928    out[i].imageID    = in[i].imageID;
    30     out[i].qPSF       = in[i].qPSF;
     29    out[i].psfQual    = in[i].psfQual;
    3130    out[i].psfChisq   = in[i].psfChisq;
    3231    out[i].crNsigma   = in[i].crNsigma;
     
    4039    out[i].dbFlags    = in[i].dbFlags;
    4140    out[i].photFlags  = in[i].photFlags;
    42     out[i].stargal    = in[i].stargal;
    43     out[i].dophot     = in[i].dophot;
     41
     42    // changed or added for PS1_DEV_2
     43    out[i].Map        = in[i].Mgal;
     44    out[i].dMcal      = 0;
     45
     46    // changed or added for PS1_V1
     47    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
     48    out[i].t_msec     = 0;
     49    out[i].extID      = 0;
     50    out[i].objID      = 0;
     51    out[i].catID      = 0;
     52    out[i].Mxx        = 0.0;
     53    out[i].Mxy        = 0.0;
     54    out[i].Myy        = 0.0;
     55    out[i].posangle   = 0;
     56    out[i].pltscale   = 0;
     57    out[i].psfNdof    = 0;
     58    out[i].psfNpix    = 0;
    4459  }
    4560  return (out);
     
    5873    out[i].M          = in[i].M;
    5974    out[i].Mcal       = in[i].Mcal;
    60     out[i].Mgal       = in[i].Map;
    6175    out[i].dM         = in[i].dM;
    6276    out[i].dt         = in[i].dt;
     
    7185    out[i].detID      = in[i].detID;
    7286    out[i].imageID    = in[i].imageID;
    73     out[i].qPSF       = in[i].qPSF;
     87    out[i].psfQual    = in[i].psfQual;
    7488    out[i].psfChisq   = in[i].psfChisq;
    7589    out[i].crNsigma   = in[i].crNsigma;
     
    8296    out[i].dYccd      = in[i].dYccd;
    8397    out[i].dbFlags    = in[i].dbFlags;
    84     out[i].photFlags  = in[i].photFlags;
    85     out[i].stargal    = in[i].stargal;
    86     out[i].dophot     = in[i].dophot;
     98
     99    // changed or added for PS1_DEV_2
     100    out[i].Mgal       = in[i].Map;
     101
     102    // changed or added for PS1_V1
     103    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
     104    out[i].dophot     = in[i].photFlags >> 16;
    87105  }
    88106  return (out);
     
    101119    out[i].D             = in[i].D;     
    102120    out[i].Xp            = in[i].Xp;     
    103     out[i].Nmeasure      = in[i].Nm;     
    104     out[i].Nmissing      = in[i].Nn;     
    105     out[i].code          = in[i].code;   
    106     out[i].measureOffset = in[i].offset;
    107     out[i].missingOffset = in[i].missing;
    108121    out[i].dR            = in[i].dR;
    109122    out[i].dD            = in[i].dD;
     
    116129    out[i].objID         = in[i].objID;
    117130    out[i].catID         = in[i].catID;
     131
     132    // changed or added for PS1_DEV_2
     133    out[i].Nmeasure      = in[i].Nm;     
     134    out[i].Nmissing      = in[i].Nn;     
     135    out[i].measureOffset = in[i].offset;
     136    out[i].missingOffset = in[i].missing;
     137    out[i].Nextend       = 0;
     138    out[i].extendOffset  = 0;
     139
     140    // changed or added for PS1_V1
     141    out[i].flags         = in[i].code;   
     142    out[i].ChiSq         = 0.0;
     143    out[i].Npos          = 0.0;
     144    out[i].extID         = 0;
    118145  }
    119146  return (out);
     
    129156
    130157  for (i = 0; i < Nvalues; i++) {
    131     out[i].R        = in[i].R;     
    132     out[i].D        = in[i].D;     
    133     out[i].Xp       = in[i].Xp;     
    134     out[i].Nm       = in[i].Nmeasure;     
    135     out[i].Nn       = in[i].Nmissing;     
    136     out[i].code     = in[i].code;   
    137     out[i].offset   = in[i].measureOffset;
    138     out[i].missing  = in[i].missingOffset;
    139     out[i].dR       = in[i].dR;
    140     out[i].dD       = in[i].dD;
    141     out[i].uR       = in[i].uR;
    142     out[i].uD       = in[i].uD;
    143     out[i].duR      = in[i].duR;
    144     out[i].duD      = in[i].duD;
    145     out[i].P        = in[i].P;
    146     out[i].dP       = in[i].dP;
    147     out[i].objID    = in[i].objID;
    148     out[i].catID    = in[i].catID;
     158    out[i].R             = in[i].R;     
     159    out[i].D             = in[i].D;     
     160    out[i].Xp            = in[i].Xp;     
     161    out[i].dR            = in[i].dR;
     162    out[i].dD            = in[i].dD;
     163    out[i].uR            = in[i].uR;
     164    out[i].uD            = in[i].uD;
     165    out[i].duR           = in[i].duR;
     166    out[i].duD           = in[i].duD;
     167    out[i].P             = in[i].P;
     168    out[i].dP            = in[i].dP;
     169    out[i].objID         = in[i].objID;
     170    out[i].catID         = in[i].catID;
     171
     172    // changed or added for PS1_DEV_2
     173    out[i].Nm            = in[i].Nmeasure;     
     174    out[i].Nn            = in[i].Nmissing;     
     175    out[i].offset        = in[i].measureOffset;
     176    out[i].missing       = in[i].missingOffset;
     177
     178    // changed or added for PS1_V1
     179    out[i].code          = in[i].flags;   
    149180  }
    150181  return (out);
     
    164195    out[i].Ncode = in[i].Ncode;
    165196    out[i].Nused = in[i].Nused;
     197
     198    // changed or added for PS1_V1
     199    out[i].M_20  = 0;     
     200    out[i].M_80  = 0;     
    166201 }
    167202  return (out);
     
    218253    out[i].fwhm_y           = in[i].fwhm_y;
    219254    out[i].trate            = in[i].trate;
    220     out[i].code             = in[i].code;
    221255    out[i].ccdnum           = in[i].ccdnum;
    222256    out[i].imageID          = in[i].imageID;
     
    237271    out[i].Mxyyy            = in[i].Mxyyy;
    238272    out[i].Myyyy            = in[i].Myyyy;
     273
     274    // changed or added for PS1_DEV_2
     275    out[i].externID         = 0;
     276    out[i].sourceID         = 0;
     277
     278    // changed or added for PS1_V1
     279    out[i].flags            = in[i].code;
     280    out[i].parentID         = 0;
    239281  }
    240282  return (out);
     
    275317    out[i].fwhm_y           = in[i].fwhm_y;
    276318    out[i].trate            = in[i].trate;
    277     out[i].code             = in[i].code;
    278319    out[i].ccdnum           = in[i].ccdnum;
    279320    out[i].imageID          = in[i].imageID;
     
    294335    out[i].Mxyyy            = in[i].Mxyyy;
    295336    out[i].Myyyy            = in[i].Myyyy;
     337
     338    // changed or added for PS1_V1
     339    out[i].code             = in[i].flags;
     340  }
     341  return (out);
     342}
     343
     344PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
     345
     346  int i;
     347  PhotCode *out;
     348
     349  ALLOCATE (out, PhotCode, Nvalues);
     350
     351  for (i = 0; i < Nvalues; i++) {
     352    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
     353    out[i].name[31] = 0; // force termination
     354
     355    out[i].code  = in[i].code;         
     356    out[i].type  = in[i].type;         
     357    out[i].C     = in[i].C;           
     358    out[i].dC    = in[i].dC;           
     359    out[i].dX    = in[i].dX;           
     360    out[i].K     = in[i].K;           
     361    out[i].c1    = in[i].c1;           
     362    out[i].c2    = in[i].c2;           
     363    out[i].equiv = in[i].equiv;       
     364    out[i].Nc    = in[i].Nc;           
     365    memcpy (out[i].X, in[i].X, 4*sizeof(float));           
     366
     367    out[i].astromErrMagScale = in[i].astromErrMagScale;
     368    out[i].photomErrSys      = in[i].photomErrSys;
     369
     370    // changed or added for PS1_DEV_2
     371    out[i].astromErrSys      = 0.0;
     372    out[i].astromErrScale    = 0.0;
     373
     374    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
     375    out[i].photomPoorMask      = 0;
     376    out[i].photomBadMask       = 0;
     377    out[i].astromPoorMask      = 0;
     378    out[i].astromBadMask       = 0;
    296379  }
    297380  return (out);
     
    323406    out[i].astromErrMagScale = out[i].astromErrMagScale;
    324407    out[i].photomErrSys      = out[i].photomErrSys;
    325 
    326   }
    327   return (out);
    328 }
    329 
    330 PhotCode *PhotCode_PS1_DEV_1_To_Internal (PhotCode_PS1_DEV_1 *in, int Nvalues) {
    331 
    332   int i;
    333   PhotCode *out;
    334 
    335   ALLOCATE (out, PhotCode, Nvalues);
    336 
    337   for (i = 0; i < Nvalues; i++) {
    338     strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
    339     out[i].name[31] = 0; // force termination
    340 
    341     out[i].code  = in[i].code;         
    342     out[i].type  = in[i].type;         
    343     out[i].C     = in[i].C;           
    344     out[i].dC    = in[i].dC;           
    345     out[i].dX    = in[i].dX;           
    346     out[i].K     = in[i].K;           
    347     out[i].c1    = in[i].c1;           
    348     out[i].c2    = in[i].c2;           
    349     out[i].equiv = in[i].equiv;       
    350     out[i].Nc    = in[i].Nc;           
    351 
    352     // not defined in PS1_DEV_1
    353     out[i].astromErrSys      = 0.0;
    354     out[i].astromErrScale    = 0.0;
    355     out[i].astromErrMagScale = in[i].astromErrMagScale;
    356     out[i].photomErrSys      = in[i].photomErrSys;
    357 
    358     memcpy (out[i].X, in[i].X, 4*sizeof(float));           
    359 
    360     out[i].photomPoorMask      = 0;
    361     out[i].photomBadMask       = 0;
    362     out[i].astromPoorMask      = 0;
    363     out[i].astromBadMask       = 0;
    364   }
    365   return (out);
    366 }
     408  }
     409  return (out);
     410}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_2.c

    r19185 r21536  
    2929    out[i].detID      = in[i].detID;
    3030    out[i].imageID    = in[i].imageID;
    31     out[i].qPSF       = in[i].qPSF;
     31    out[i].psfQual    = in[i].psfQual;
    3232    out[i].psfChisq   = in[i].psfChisq;
    3333    out[i].crNsigma   = in[i].crNsigma;
     
    4040    out[i].dYccd      = in[i].dYccd;
    4141    out[i].dbFlags    = in[i].dbFlags;
    42     out[i].photFlags  = in[i].photFlags;
    43     out[i].stargal    = in[i].stargal;
    44     out[i].dophot     = in[i].dophot;
     42
     43    // changed or added for PS1_V1
     44    out[i].photFlags  = in[i].photFlags | (in[i].dophot << 16);
     45    out[i].t_msec     = 0;
     46    out[i].extID      = 0;
     47    out[i].objID      = 0;
     48    out[i].catID      = 0;
     49    out[i].Mxx        = 0.0;
     50    out[i].Mxy        = 0.0;
     51    out[i].Myy        = 0.0;
     52    out[i].posangle   = 0;
     53    out[i].pltscale   = 0;
     54    out[i].psfNdof    = 0;
     55    out[i].psfNpix    = 0;
    4556  }
    4657  return (out);
     
    7384    out[i].detID      = in[i].detID;
    7485    out[i].imageID    = in[i].imageID;
    75     out[i].qPSF       = in[i].qPSF;
     86    out[i].psfQual    = in[i].psfQual;
    7687    out[i].psfChisq   = in[i].psfChisq;
    7788    out[i].crNsigma   = in[i].crNsigma;
     
    8495    out[i].dYccd      = in[i].dYccd;
    8596    out[i].dbFlags    = in[i].dbFlags;
    86     out[i].photFlags  = in[i].photFlags;
    87     out[i].stargal    = in[i].stargal;
    88     out[i].dophot     = in[i].dophot;
     97
     98    // changed or added for PS1_V1
     99    out[i].photFlags  = in[i].photFlags & 0x0000ffff;
     100    out[i].dophot     = in[i].photFlags >> 16;
    89101  }
    90102  return (out);
     
    114126    out[i].Nmissing      = in[i].Nmissing;     
    115127    out[i].Nextend       = in[i].Nextend;     
    116     out[i].code          = in[i].code;   
    117128    out[i].measureOffset = in[i].measureOffset;
    118129    out[i].missingOffset = in[i].missingOffset;
     
    120131    out[i].objID         = in[i].objID;
    121132    out[i].catID         = in[i].catID;
     133
     134    // changed or added for PS1_V1
     135    out[i].flags         = in[i].code;   
     136    out[i].ChiSq         = 0.0;
     137    out[i].Npos          = 0.0;
     138    out[i].extID         = 0;
    122139  }
    123140  return (out);
     
    147164    out[i].Nmissing      = in[i].Nmissing;     
    148165    out[i].Nextend       = in[i].Nextend;     
    149     out[i].code          = in[i].code;   
    150166    out[i].measureOffset = in[i].measureOffset;
    151167    out[i].missingOffset = in[i].missingOffset;
     
    153169    out[i].objID         = in[i].objID;
    154170    out[i].catID         = in[i].catID;
     171
     172    // changed or added for PS1_V1
     173    out[i].code          = in[i].flags;   
    155174  }
    156175  return (out);
     
    170189    out[i].Ncode = in[i].Ncode;
    171190    out[i].Nused = in[i].Nused;
     191
     192    // changed or added for PS1_V1
     193    out[i].M_20  = 0;     
     194    out[i].M_80  = 0;     
    172195 }
    173196  return (out);
     
    201224    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    202225
    203     strncpy (out[i].name, in[i].name, 63); // out[128], int[64]
     226    strncpy (out[i].name, in[i].name, 63); // out[121], int[64]
    204227    out[i].name[63] = 0; // force termination
    205228
     
    224247    out[i].fwhm_y           = in[i].fwhm_y;
    225248    out[i].trate            = in[i].trate;
    226     out[i].code             = in[i].code;
    227249    out[i].ccdnum           = in[i].ccdnum;
    228250    out[i].imageID          = in[i].imageID;
     
    245267    out[i].Mxyyy            = in[i].Mxyyy;
    246268    out[i].Myyyy            = in[i].Myyyy;
     269
     270    // changed or added for PS1_V1
     271    out[i].flags            = in[i].code;
     272    out[i].parentID         = 0;
    247273  }
    248274  return (out);
     
    259285    memcpy (&out[i].coords, &in[i].coords, sizeof(Coords));
    260286
    261     strncpy (out[i].name, in[i].name, 63); // in[128], out[64]
     287    strncpy (out[i].name, in[i].name, 63); // in[121], out[64]
    262288    out[i].name[63] = 0; // force termination
    263289
     
    282308    out[i].fwhm_y           = in[i].fwhm_y;
    283309    out[i].trate            = in[i].trate;
    284     out[i].code             = in[i].code;
    285310    out[i].ccdnum           = in[i].ccdnum;
    286311    out[i].imageID          = in[i].imageID;
     
    303328    out[i].Mxyyy            = in[i].Mxyyy;
    304329    out[i].Myyyy            = in[i].Myyyy;
    305   }
    306   return (out);
    307 }
    308 
    309 PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
    310 
    311   int i;
    312   PhotCode_PS1_DEV_2 *out;
    313 
    314   ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
     330
     331    // changed or added for PS1_V1
     332    out[i].code             = in[i].flags;
     333  }
     334  return (out);
     335}
     336
     337PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
     338
     339  int i;
     340  PhotCode *out;
     341
     342  ALLOCATE (out, PhotCode, Nvalues);
    315343
    316344  for (i = 0; i < Nvalues; i++) {
     
    334362    out[i].astromErrMagScale = in[i].astromErrMagScale;
    335363    out[i].photomErrSys      = in[i].photomErrSys;
    336   }
    337   return (out);
    338 }
    339 
    340 PhotCode *PhotCode_PS1_DEV_2_To_Internal (PhotCode_PS1_DEV_2 *in, int Nvalues) {
    341 
    342   int i;
    343   PhotCode *out;
    344 
    345   ALLOCATE (out, PhotCode, Nvalues);
     364
     365    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
     366    out[i].photomPoorMask      = 0;
     367    out[i].photomBadMask       = 0;
     368    out[i].astromPoorMask      = 0;
     369    out[i].astromBadMask       = 0;
     370  }
     371  return (out);
     372}
     373
     374PhotCode_PS1_DEV_2 *PhotCode_Internal_To_PS1_DEV_2 (PhotCode *in, int Nvalues) {
     375
     376  int i;
     377  PhotCode_PS1_DEV_2 *out;
     378
     379  ALLOCATE (out, PhotCode_PS1_DEV_2, Nvalues);
    346380
    347381  for (i = 0; i < Nvalues; i++) {
     
    365399    out[i].astromErrMagScale = in[i].astromErrMagScale;
    366400    out[i].photomErrSys      = in[i].photomErrSys;
    367 
    368     out[i].photomPoorMask      = 0;
    369     out[i].photomBadMask       = 0;
    370     out[i].astromPoorMask      = 0;
    371     out[i].astromBadMask       = 0;
    372   }
    373   return (out);
    374 }
     401  }
     402  return (out);
     403}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_PS1_DEV_3.c

    r19185 r21536  
    33/* convert PS1_DEV_3 formats to internal formats */
    44
    5 // XXX EAM I am not yet ready to commit to a full PS1_DEV_3 release, but I am providing image and photcode conversion
     5// We only provide image and photcode conversion
    66
    77Image *Image_PS1_DEV_3_ToInternal (Image_PS1_DEV_3 *in, int Nvalues) {
     
    3838    out[i].fwhm_y           = in[i].fwhm_y;
    3939    out[i].trate            = in[i].trate;
    40     out[i].code             = in[i].code;
    4140    out[i].ccdnum           = in[i].ccdnum;
    4241    out[i].imageID          = in[i].imageID;
     
    5958    out[i].Mxyyy            = in[i].Mxyyy;
    6059    out[i].Myyyy            = in[i].Myyyy;
     60
     61    // changed or added for PS1_V1
     62    out[i].flags            = in[i].code;
     63    out[i].parentID         = 0;
    6164  }
    6265  return (out);
     
    9699    out[i].fwhm_y           = in[i].fwhm_y;
    97100    out[i].trate            = in[i].trate;
    98     out[i].code             = in[i].code;
    99101    out[i].ccdnum           = in[i].ccdnum;
    100102    out[i].imageID          = in[i].imageID;
     
    117119    out[i].Mxyyy            = in[i].Mxyyy;
    118120    out[i].Myyyy            = in[i].Myyyy;
     121
     122    // changed or added for PS1_V1
     123    out[i].code             = in[i].flags;
     124  }
     125  return (out);
     126}
     127
     128PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
     129
     130  int i;
     131  PhotCode *out;
     132
     133  ALLOCATE (out, PhotCode, Nvalues);
     134
     135  for (i = 0; i < Nvalues; i++) {
     136    strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
     137    out[i].name[31] = 0; // force termination
     138
     139    out[i].code  = in[i].code;         
     140    out[i].type  = in[i].type;         
     141    out[i].C     = in[i].C;           
     142    out[i].dC    = in[i].dC;           
     143    out[i].dX    = in[i].dX;           
     144    out[i].K     = in[i].K;           
     145    out[i].c1    = in[i].c1;           
     146    out[i].c2    = in[i].c2;           
     147    out[i].equiv = in[i].equiv;       
     148    out[i].Nc    = in[i].Nc;           
     149    memcpy (out[i].X, in[i].X, 4*sizeof(float));           
     150
     151    out[i].astromErrSys      = in[i].astromErrSys;
     152    out[i].astromErrScale    = in[i].astromErrScale;
     153    out[i].astromErrMagScale = in[i].astromErrMagScale;
     154    out[i].photomErrSys      = in[i].photomErrSys;
     155
     156    out[i].photomPoorMask      = in[i].photomPoorMask;
     157    out[i].photomBadMask       = in[i].photomBadMask;
     158    out[i].astromPoorMask      = in[i].astromPoorMask;
     159    out[i].astromBadMask       = in[i].astromBadMask;
    119160  }
    120161  return (out);
     
    157198}
    158199
    159 PhotCode *PhotCode_PS1_DEV_3_To_Internal (PhotCode_PS1_DEV_3 *in, int Nvalues) {
    160 
    161   int i;
    162   PhotCode *out;
    163 
    164   ALLOCATE (out, PhotCode, Nvalues);
    165 
    166   for (i = 0; i < Nvalues; i++) {
    167     strncpy (out[i].name, in[i].name, 31); // out[32], in[32]
    168     out[i].name[31] = 0; // force termination
    169 
    170     out[i].code  = in[i].code;         
    171     out[i].type  = in[i].type;         
    172     out[i].C     = in[i].C;           
    173     out[i].dC    = in[i].dC;           
    174     out[i].dX    = in[i].dX;           
    175     out[i].K     = in[i].K;           
    176     out[i].c1    = in[i].c1;           
    177     out[i].c2    = in[i].c2;           
    178     out[i].equiv = in[i].equiv;       
    179     out[i].Nc    = in[i].Nc;           
    180     memcpy (out[i].X, in[i].X, 4*sizeof(float));           
    181 
    182     out[i].astromErrSys      = in[i].astromErrSys;
    183     out[i].astromErrScale    = in[i].astromErrScale;
    184     out[i].astromErrMagScale = in[i].astromErrMagScale;
    185     out[i].photomErrSys      = in[i].photomErrSys;
    186 
    187     out[i].photomPoorMask      = in[i].photomPoorMask;
    188     out[i].photomBadMask       = in[i].photomBadMask;
    189     out[i].astromPoorMask      = in[i].astromPoorMask;
    190     out[i].astromBadMask       = in[i].astromBadMask;
    191   }
    192   return (out);
    193 }
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_elixir.c

    r19185 r21536  
    1010
    1111  for (i = 0; i < Nvalues; i++) {
     12    out[i].FWx      = in[i].FWx;
     13    out[i].t        = in[i].t;
     14    out[i].averef   = in[i].averef;
     15
     16    // changed for PANSTARRS_DEV_0
    1217    out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
    1318    out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
     
    1621    out[i].dt       = (in[i].dt      == NAN_S_SHORT) ? NAN : in[i].dt     * 0.001;
    1722    out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
    18 
    19     // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
    20     // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
    2123    out[i].Map      = (in[i].Mgal    == NAN_S_SHORT) ? NAN : in[i].Mgal   * 0.001;
    2224    out[i].airmass  = (in[i].airmass == NAN_S_SHORT) ? NAN : in[i].airmass* 0.001;
    23     out[i].FWx      = in[i].FWx;
    2425    out[i].FWy      = in[i].fwy * in[i].FWx * 0.01;
    2526    out[i].theta    = in[i].theta*(0x10000 / 0x100);
    26     out[i].dophot   = in[i].dophot;
    2727    out[i].photcode = in[i].source;
    28     out[i].t        = in[i].t;
    29     out[i].averef   = in[i].averef;
    30     out[i].dbFlags  = in[i].flags;
    3128   
    32     /* these can be determined if needed / desired */
    33     out[i].Xccd     = 0;
    34     out[i].Yccd     = 0;
    35     out[i].dXccd    = 0;
    36     out[i].dYccd    = 0;
    37 
    38     /* these do not have a corresponding value */
     29    // added for PANSTARRS_DEV_0
     30    out[i].Xccd      = 0;  // determine on-the-fly
     31    out[i].Yccd      = 0;  // determine on-the-fly
     32    out[i].dXccd     = 0;
     33    out[i].dYccd     = 0;
    3934    out[i].az        = 0;
    40     out[i].stargal   = 0;
    4135    out[i].Sky       = 0;
    4236    out[i].dSky      = 0;
    43     out[i].qPSF      = 0;
     37    out[i].psfQual   = 0;
    4438    out[i].psfChisq  = 0;
    4539    out[i].crNsigma  = 0;
    4640    out[i].extNsigma = 0;
    47     out[i].photFlags = 0;
    48 
    49     /* XXX add these later */
    50     out[i].detID = 0;
    51     out[i].imageID = 0;
     41    out[i].detID     = 0;  // determine on-the-fly
     42    out[i].imageID   = 0;  // determine on-the-fly
     43
     44    // changed or added for PS1_DEV_1 (2008.02.26)
     45    out[i].dbFlags    = in[i].flags;
     46    out[i].detID      = 0;
     47    out[i].imageID    = 0;
     48
     49    // changed or added for PS1_DEV_2
     50    out[i].Map        = in[i].Mgal;
     51    out[i].dMcal      = 0;
     52
     53    // changed or added for PS1_V1
     54    out[i].photFlags  = in[i].dophot << 16;
     55    out[i].t_msec     = 0;
     56    out[i].extID      = 0;
     57    out[i].objID      = 0;
     58    out[i].catID      = 0;
     59    out[i].Mxx        = 0.0;
     60    out[i].Mxy        = 0.0;
     61    out[i].Myy        = 0.0;
     62    out[i].posangle   = 0;
     63    out[i].pltscale   = 0;
     64    out[i].psfNdof    = 0;
     65    out[i].psfNpix    = 0;
    5266  }
    5367  return (out);
     
    6377
    6478  for (i = 0; i < Nvalues; i++) {
     79    out[i].FWx     = in[i].FWx;
     80    out[i].t       = in[i].t;
     81    out[i].averef  = in[i].averef;
     82
     83    // changed for PANSTARRS_DEV_0
    6584    out[i].dR       = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
    6685    out[i].dD       = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
     
    7190    out[i].Mgal     = isnan(in[i].Map    ) ? NAN_S_SHORT : in[i].Map     * 1000.0;
    7291    out[i].airmass  = isnan(in[i].airmass) ? NAN_S_SHORT : in[i].airmass * 1000.0;
     92    out[i].fwy      = in[i].FWy * 100.0 / in[i].FWx;
     93    out[i].theta    = in[i].theta*(0x100/ 0x10000);
     94    out[i].source   = in[i].photcode;
    7395
    7496    if (out[i].M < 0) {
     
    7698    }
    7799
    78     out[i].FWx     = in[i].FWx;
    79     out[i].fwy     = in[i].FWy * 100.0 / in[i].FWx;
    80     out[i].theta   = in[i].theta*(0x100/ 0x10000);
    81     out[i].dophot  = in[i].dophot;
    82     out[i].source  = in[i].photcode;
    83     out[i].t       = in[i].t;
    84     out[i].averef  = in[i].averef;
     100    // changed or added for PS1_DEV_1 (2008.02.26)
    85101    out[i].flags   = in[i].dbFlags;
     102
     103    // changed or added for PS1_V1
     104    out[i].dophot  = in[i].photFlags >> 16;
    86105  }
    87106  return (out);
     
    101120    out[i].D             = in[i].D;     
    102121    out[i].Xp            = in[i].Xp;     
    103     out[i].Nmeasure      = in[i].Nm;     
    104     out[i].Nmissing      = in[i].Nn;     
    105     out[i].code          = in[i].code;   
    106     out[i].measureOffset = in[i].offset;
    107     out[i].missingOffset = in[i].missing;
    108 
    109     /* these don't exist in Elixir */
     122
     123    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
     124    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
     125    primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;     
     126    primary[0][i].Xm    = in[i].Xm;     
     127
     128    primary[0][i].Ncode = 0;     
     129    primary[0][i].Nused = 0;
     130
     131    // added for PANSTARRS_DEV_0
    110132    out[i].dR      = 0;
    111133    out[i].dD      = 0;
     
    116138    out[i].P       = 0;
    117139    out[i].dP      = 0;
    118 
    119     /* XXX add these later */
    120     out[i].objID   = 0;
    121     out[i].catID   = 0;
    122 
    123     primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    124     primary[0][i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM * 0.001;     
    125     primary[0][i].Xm    = in[i].Xm;     
    126     primary[0][i].Ncode = 0;     
    127     primary[0][i].Nused = 0;
     140    out[i].objID   = 0; // determine on-the-fly
     141    out[i].catID   = 0; // determine on-the-fly
     142
     143    // changed or added for PS1_DEV_2
     144    out[i].Nmeasure      = in[i].Nm;     
     145    out[i].Nmissing      = in[i].Nn;     
     146    out[i].measureOffset = in[i].offset;
     147    out[i].missingOffset = in[i].missing;
     148    out[i].Nextend       = 0;
     149    out[i].extendOffset  = 0;
     150
     151    // changed or added for PS1_V1
     152    out[i].flags         = in[i].code;   
     153    out[i].ChiSq         = 0.0;
     154    out[i].Npos          = 0.0;
     155    out[i].extID         = 0;
    128156  }
    129157  return (out);
     
    142170    out[i].D       = in[i].D;     
    143171    out[i].Xp      = in[i].Xp;     
    144     out[i].Nm      = in[i].Nmeasure;     
    145     out[i].Nn      = in[i].Nmissing;     
    146     out[i].code    = in[i].code;   
    147     out[i].offset  = in[i].measureOffset;
    148     out[i].missing = in[i].missingOffset;
    149 
     172
     173    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
    150174    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
    151175    out[i].dM      = isnan(primary[i].dM) ? NAN_S_SHORT : primary[i].dM  * 1000.0;
    152176    out[i].Xm      = primary[i].Xm;     
     177
     178    // changed or added for PS1_DEV_2
     179    out[i].Nm      = in[i].Nmeasure;     
     180    out[i].Nn      = in[i].Nmissing;     
     181    out[i].offset  = in[i].measureOffset;
     182    out[i].missing = in[i].missingOffset;
     183
     184    // changed or added for PS1_V1
     185    out[i].code    = in[i].flags;   
    153186  }
    154187  return (out);
     
    164197
    165198  for (i = 0; i < Nvalues; i++) {
     199    out[i].Xm    = in[i].Xm;     
     200
     201    // added or changed for PANSTARRS_DEV_0
    166202    out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M   * 0.001;
    167203    out[i].dM    = (in[i].dM == NAN_S_SHORT) ? NAN : in[i].dM  * 0.001;
    168     out[i].Xm    = in[i].Xm;     
    169204    out[i].Ncode = 0;
    170205    out[i].Nused = 0;
     206
     207    // changed or added for PS1_V1
     208    out[i].M_20  = 0;     
     209    out[i].M_80  = 0;     
    171210  }
    172211  return (out);
     
    182221
    183222  for (i = 0; i < Nvalues; i++) {
     223    out[i].Xm    = in[i].Xm;     
     224
     225    // added or changed for PANSTARRS_DEV_0
    184226    out[i].M     = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M   * 1000.0;
    185227    out[i].dM    = isnan(in[i].dM) ? NAN_S_SHORT : in[i].dM  * 1000.0;
    186     out[i].Xm    = in[i].Xm;     
    187228  }
    188229  return (out);
     
    207248    out[i].NX               = in[i].NX;
    208249    out[i].NY               = in[i].NY;
    209     out[i].secz             = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
    210     out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
    211     out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
    212     out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
    213     out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
    214250    out[i].Xm               = in[i].Xm;
    215251    out[i].photcode         = in[i].source;
     
    221257    out[i].fwhm_y           = in[i].fwhm_y;
    222258    out[i].trate            = in[i].trate;
    223     out[i].code             = in[i].code;
    224259    out[i].ccdnum           = in[i].ccdnum;
    225260
     
    240275    out[i].Myyyy            = in[i].Myyyy;
    241276
    242     /* XXX add these later */
    243     out[i].imageID = 0;
    244 
    245     // not available in ELIXIR
     277    // added or changed for PANSTARRS_DEV_0
     278    out[i].secz             = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
     279    out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
     280    out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
     281    out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     282    out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
    246283    out[i].sidtime          = NAN;
    247284    out[i].latitude         = NAN;
     285    out[i].imageID          = 0; // determine on-the-fly
     286
     287    // changed or added for PS1_DEV_2
     288    out[i].externID         = 0;
     289    out[i].sourceID         = 0;
     290
     291    // changed or added for PS1_V1
     292    out[i].flags            = in[i].code;
     293    out[i].parentID         = 0;
    248294  }
    249295  return (out);
     
    268314    out[i].NX               = in[i].NX;
    269315    out[i].NY               = in[i].NY;
    270     out[i].secz             = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
    271     out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
    272     out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
    273     out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
    274     out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
     316
    275317    out[i].Xm               = in[i].Xm;
    276318    out[i].source           = in[i].photcode;
     
    282324    out[i].fwhm_y           = in[i].fwhm_y;
    283325    out[i].trate            = in[i].trate;
    284     out[i].code             = in[i].code;
    285326    out[i].ccdnum           = in[i].ccdnum;
    286327
     
    300341    out[i].Mxyyy            = in[i].Mxyyy;
    301342    out[i].Myyyy            = in[i].Myyyy;
    302   }
    303   return (out);
    304 }
    305 
    306 PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
    307 
    308   int i;
    309   PhotCode_Elixir *out;
    310 
    311   ALLOCATE (out, PhotCode_Elixir, Nvalues);
     343
     344    // added or changed for PANSTARRS_DEV_0
     345    out[i].secz             = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
     346    out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
     347    out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
     348    out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
     349    out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
     350
     351    // changed or added for PS1_V1
     352    out[i].code             = in[i].flags;
     353  }
     354  return (out);
     355}
     356
     357PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
     358
     359  int i;
     360  PhotCode *out;
     361
     362  ALLOCATE (out, PhotCode, Nvalues);
    312363
    313364  for (i = 0; i < Nvalues; i++) {
     
    326377    out[i].Nc    = in[i].Nc;           
    327378    memcpy (out[i].X, in[i].X, 4*sizeof(float));           
    328   }
    329   return (out);
    330 }
    331 
    332 PhotCode *PhotCode_Elixir_To_Internal (PhotCode_Elixir *in, int Nvalues) {
    333 
    334   int i;
    335   PhotCode *out;
    336 
    337   ALLOCATE (out, PhotCode, Nvalues);
     379
     380    // changed or added for PS1_DEV_1
     381    out[i].astromErrMagScale = 0.0;
     382    out[i].photomErrSys      = 0.0;
     383
     384    // changed or added for PS1_DEV_2
     385    out[i].astromErrSys      = 0.0;
     386    out[i].astromErrScale    = 0.0;
     387
     388    // changed or added for PS1_V1 (also PS1_DEV_3, deprecated)
     389    out[i].photomPoorMask      = 0;
     390    out[i].photomBadMask       = 0;
     391    out[i].astromPoorMask      = 0;
     392    out[i].astromBadMask       = 0;
     393  }
     394  return (out);
     395}
     396
     397PhotCode_Elixir *PhotCode_Internal_To_Elixir (PhotCode *in, int Nvalues) {
     398
     399  int i;
     400  PhotCode_Elixir *out;
     401
     402  ALLOCATE (out, PhotCode_Elixir, Nvalues);
    338403
    339404  for (i = 0; i < Nvalues; i++) {
     
    352417    out[i].Nc    = in[i].Nc;           
    353418    memcpy (out[i].X, in[i].X, 4*sizeof(float));           
    354 
    355     // not defined in Elixir:
    356     out[i].astromErrSys      = 0.0;
    357     out[i].astromErrScale    = 0.0;
    358     out[i].astromErrMagScale = 0.0;
    359     out[i].photomErrSys      = 0.0;
    360 
    361     out[i].photomPoorMask      = 0;
    362     out[i].photomBadMask       = 0;
    363     out[i].astromPoorMask      = 0;
    364     out[i].astromBadMask       = 0;
    365   }
    366   return (out);
    367 }
     419  }
     420  return (out);
     421}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_loneos.c

    r19185 r21536  
    1010
    1111  for (i = 0; i < Nvalues; i++) {
    12     out[i].dR        = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
    13     out[i].dD        = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
    14     out[i].M         = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
    15     out[i].dM        = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
    16     out[i].Mcal      = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
    17     out[i].dophot    = in[i].dophot;
    18     out[i].photcode  = in[i].source;
    19     out[i].t         = in[i].t;
    20 
    21     /* flags and averef are now split */
     12    out[i].t        = in[i].t;
     13
     14    // added or changed for ELIXIR
    2215    out[i].averef    =  in[i].averef & 0x00ffffff;
    2316    out[i].dbFlags   = (in[i].averef & 0xff000000) >> 24;
    24 
    25     /* these values don't exist in the Loneos format */
    26 
    27     // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
    28     // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
    29     out[i].Map       = out[i].M;
     17    out[i].t         = in[i].t;
    3018    out[i].dt        = 0;
    3119    out[i].airmass   = 0;
     20    out[i].FWy       = 0;
     21    out[i].FWx       = 0;
     22    out[i].theta     = 0;
     23
     24    // changed for PANSTARRS_DEV_0
     25    out[i].dR       = (in[i].dR      == NAN_S_SHORT) ? NAN : in[i].dR     * 0.01;
     26    out[i].dD       = (in[i].dD      == NAN_S_SHORT) ? NAN : in[i].dD     * 0.01;
     27    out[i].M        = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
     28    out[i].dM       = (in[i].dM      == NAN_U_CHAR)  ? NAN : in[i].dM     * 0.001;
     29    out[i].Mcal     = (in[i].Mcal    == NAN_S_SHORT) ? NAN : in[i].Mcal   * 0.001;
     30    out[i].Map      = (in[i].M       == NAN_S_SHORT) ? NAN : in[i].M      * 0.001;
     31    out[i].photcode = in[i].source;
     32   
     33    // added for PANSTARRS_DEV_0
     34    out[i].Xccd      = 0;  // determine on-the-fly
     35    out[i].Yccd      = 0;  // determine on-the-fly
     36    out[i].dXccd     = 0;
     37    out[i].dYccd     = 0;
    3238    out[i].az        = 0;
    33     out[i].FWx       = 0;
    34     out[i].FWy       = 0;
    35     out[i].theta     = 0;
    36     out[i].stargal   = 0;
    3739    out[i].Sky       = 0;
    3840    out[i].dSky      = 0;
    39     out[i].qPSF      = 0;
     41    out[i].psfQual   = 0;
    4042    out[i].psfChisq  = 0;
    4143    out[i].crNsigma  = 0;
    4244    out[i].extNsigma = 0;
    43     out[i].photFlags = 0;
    44 
    45     /* these can be determined if needed / desired */
    46     out[i].Xccd     = 0;
    47     out[i].Yccd     = 0;
    48     out[i].dXccd    = 0;
    49     out[i].dYccd    = 0;
    50 
    51     /* XXX add these later */
    52     out[i].detID = 0;
    53     out[i].imageID = 0;
     45    out[i].detID     = 0;  // determine on-the-fly
     46    out[i].imageID   = 0;  // determine on-the-fly
     47
     48    // changed or added for PS1_DEV_1 (2008.02.26)
     49    out[i].detID      = 0;
     50    out[i].imageID    = 0;
     51
     52    // changed or added for PS1_DEV_2
     53    out[i].dMcal      = 0;
     54
     55    // changed or added for PS1_V1
     56    out[i].photFlags  = in[i].dophot << 16;
     57    out[i].t_msec     = 0;
     58    out[i].extID      = 0;
     59    out[i].objID      = 0;
     60    out[i].catID      = 0;
     61    out[i].Mxx        = 0.0;
     62    out[i].Mxy        = 0.0;
     63    out[i].Myy        = 0.0;
     64    out[i].posangle   = 0;
     65    out[i].pltscale   = 0;
     66    out[i].psfNdof    = 0;
     67    out[i].psfNpix    = 0;
    5468  }
    5569  return (out);
     
    6579
    6680  for (i = 0; i < Nvalues; i++) {
     81
     82    // changed for PANSTARRS_DEV_0
    6783    out[i].dR     = isnan(in[i].dR     ) ? NAN_S_SHORT : in[i].dR      *  100.0;
    6884    out[i].dD     = isnan(in[i].dD     ) ? NAN_S_SHORT : in[i].dD      *  100.0;
     
    7086    out[i].dM     = isnan(in[i].dM     ) ? NAN_U_CHAR  : in[i].dM      * 1000.0;
    7187    out[i].Mcal   = isnan(in[i].Mcal   ) ? NAN_S_SHORT : in[i].Mcal    * 1000.0;
    72     out[i].dophot = in[i].dophot;
    7388    out[i].source = in[i].photcode;
    7489    out[i].t      = in[i].t;
     
    7691    /* flags and averef are merged in Loneos */
    7792    out[i].averef =  (in[i].averef & 0x00ffffff) | (in[i].dbFlags << 24);
     93
     94    // changed or added for PS1_V1
     95    out[i].dophot  = in[i].photFlags >> 16;
    7896  }
    7997  return (out);
     
    93111    out[i].D             = in[i].D;     
    94112    out[i].Xp            = in[i].Xp;     
    95     out[i].Nmeasure      = in[i].Nm;     
    96     out[i].Nmissing      = in[i].Nn;     
    97     out[i].code          = in[i].code;   
    98     out[i].measureOffset = in[i].offset;
    99     out[i].missingOffset = in[i].missing;
    100 
    101     /* these don't exist in Loneos */
     113
     114    // added for ELIXIR
     115    primary[0][i].dM    = NAN;
     116
     117    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
     118    primary[0][i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
     119    primary[0][i].Xm    = in[i].Xm;     
     120    primary[0][i].Ncode = 0;     
     121    primary[0][i].Nused = 0;
     122
     123    // added for PANSTARRS_DEV_0
    102124    out[i].dR      = 0;
    103125    out[i].dD      = 0;
     
    108130    out[i].P       = 0;
    109131    out[i].dP      = 0;
    110 
    111     /* XXX add these later */
    112     out[i].objID   = 0;
    113     out[i].catID   = 0;
    114 
    115     primary[0][i].M  = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M  * 0.001;     
    116     primary[0][i].Xm = in[i].Xm;     
    117     primary[0][i].dM = NAN;
    118     primary[0][i].Ncode = 0;     
    119     primary[0][i].Nused = 0;
     132    out[i].objID   = 0; // determine on-the-fly
     133    out[i].catID   = 0; // determine on-the-fly
     134
     135    // changed or added for PS1_DEV_2
     136    out[i].Nmeasure      = in[i].Nm;     
     137    out[i].Nmissing      = in[i].Nn;     
     138    out[i].measureOffset = in[i].offset;
     139    out[i].missingOffset = in[i].missing;
     140    out[i].Nextend       = 0;
     141    out[i].extendOffset  = 0;
     142
     143    // changed or added for PS1_V1
     144    out[i].flags         = in[i].code;   
     145    out[i].ChiSq         = 0.0;
     146    out[i].Npos          = 0.0;
     147    out[i].extID         = 0;
    120148  }
    121149  return (out);
     
    134162    out[i].D       = in[i].D;     
    135163    out[i].Xp      = in[i].Xp;     
     164
     165    // changed for PANSTARRS_DEV_0 (moved from Average to Measure)
     166    out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
     167    out[i].Xm      = primary[i].Xm;     
     168
     169    // changed or added for PS1_DEV_2
    136170    out[i].Nm      = in[i].Nmeasure;     
    137171    out[i].Nn      = in[i].Nmissing;     
    138     out[i].code    = in[i].code;   
    139172    out[i].offset  = in[i].measureOffset;
    140173    out[i].missing = in[i].missingOffset;
    141174
    142     out[i].M       = isnan(primary[i].M)  ? NAN_S_SHORT : primary[i].M   * 1000.0;
    143     out[i].Xm      = primary[i].Xm;     
     175    // changed or added for PS1_V1
     176    out[i].code    = in[i].flags;   
    144177  }
    145178  return (out);
     
    155188
    156189  for (i = 0; i < Nvalues; i++) {
     190    out[i].Xm    = in[i].Xm;     
     191
     192    // added for ELIXIR
     193    out[i].dM    = NAN;
     194
     195    // added or changed for PANSTARRS_DEV_0
    157196    out[i].M     = (in[i].M  == NAN_S_SHORT) ? NAN : in[i].M * 0.001;
    158     out[i].Xm    = in[i].Xm;     
    159     out[i].dM    = NAN;
    160197    out[i].Ncode = 0;
    161198    out[i].Nused = 0;
     199
     200    // changed or added for PS1_V1
     201    out[i].M_20  = 0;     
     202    out[i].M_80  = 0;     
    162203  }
    163204  return (out);
     
    173214
    174215  for (i = 0; i < Nvalues; i++) {
     216    out[i].Xm   = in[i].Xm;     
     217
     218    // added or changed for PANSTARRS_DEV_0
    175219    out[i].M    = isnan(in[i].M)  ? NAN_S_SHORT : in[i].M * 1000.0;
    176     out[i].Xm   = in[i].Xm;     
    177220  }
    178221  return (out);
     
    197240    out[i].NX               = in[i].NX;
    198241    out[i].NY               = in[i].NY;
    199 
    200     out[i].secz             = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
    201     out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
    202     out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
    203     out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
    204     out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
    205242
    206243    out[i].Xm               = in[i].Xm;
     
    213250    out[i].fwhm_y           = in[i].fwhm_y;
    214251    out[i].trate            = in[i].trate;
    215     out[i].code             = in[i].code;
    216252    out[i].ccdnum           = in[i].ccdnum;
     253
    217254    out[i].order            = in[i].order;
    218255    out[i].Mx               = in[i].Mx;
     
    231268    out[i].Myyyy            = in[i].Myyyy;
    232269
    233     /* XXX add these later */
    234     out[i].imageID = 0;
     270    // added or changed for PANSTARRS_DEV_0
     271    out[i].secz             = (in[i].secz     == NAN_S_SHORT) ? NAN : in[i].secz     * 0.001;
     272    out[i].apmifit          = (in[i].apmifit  == NAN_S_SHORT) ? NAN : in[i].apmifit  * 0.001;
     273    out[i].dapmifit         = (in[i].dapmifit == NAN_S_SHORT) ? NAN : in[i].dapmifit * 0.001;
     274    out[i].Mcal             = (in[i].Mcal     == NAN_S_SHORT) ? NAN : in[i].Mcal     * 0.001;
     275    out[i].dMcal            = (in[i].dMcal    == NAN_S_SHORT) ? NAN : in[i].dMcal    * 0.001;
     276    out[i].sidtime          = NAN;
     277    out[i].latitude         = NAN;
     278    out[i].imageID          = 0; // determine on-the-fly
     279
     280    // changed or added for PS1_DEV_2
     281    out[i].externID         = 0;
     282    out[i].sourceID         = 0;
     283
     284    // changed or added for PS1_V1
     285    out[i].flags            = in[i].code;
     286    out[i].parentID         = 0;
    235287  }
    236288  return (out);
     
    255307    out[i].NX               = in[i].NX;
    256308    out[i].NY               = in[i].NY;
    257 
    258     out[i].secz             = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
    259     out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
    260     out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
    261     out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
    262     out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
    263309
    264310    out[i].Xm               = in[i].Xm;
     
    271317    out[i].fwhm_y           = in[i].fwhm_y;
    272318    out[i].trate            = in[i].trate;
    273     out[i].code             = in[i].code;
    274319    out[i].ccdnum           = in[i].ccdnum;
     320
    275321    out[i].order            = in[i].order;
    276322    out[i].Mx               = in[i].Mx;
     
    288334    out[i].Mxyyy            = in[i].Mxyyy;
    289335    out[i].Myyyy            = in[i].Myyyy;
    290   }
    291   return (out);
    292 }
     336
     337    // added or changed for PANSTARRS_DEV_0
     338    out[i].secz             = isnan(in[i].secz    ) ? NAN_S_SHORT : in[i].secz     * 1000.0;
     339    out[i].apmifit          = isnan(in[i].apmifit ) ? NAN_S_SHORT : in[i].apmifit  * 1000.0;
     340    out[i].dapmifit         = isnan(in[i].dapmifit) ? NAN_S_SHORT : in[i].dapmifit * 1000.0;
     341    out[i].Mcal             = isnan(in[i].Mcal    ) ? NAN_S_SHORT : in[i].Mcal     * 1000.0;
     342    out[i].dMcal            = isnan(in[i].dMcal   ) ? NAN_S_SHORT : in[i].dMcal    * 1000.0;
     343
     344    // changed or added for PS1_V1
     345    out[i].code             = in[i].flags;
     346  }
     347  return (out);
     348}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_0.c

    r19185 r21536  
    1616    out[i].Mcal       = in[i].Mcal;
    1717
    18     // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
    19     // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
    20     out[i].Map        = in[i].Mgal;
    2118    out[i].airmass    = in[i].airmass;
    2219    out[i].az         = in[i].az;
     
    2522    out[i].FWy        = in[i].FWy;
    2623    out[i].theta      = in[i].theta;
    27     out[i].dophot     = in[i].dophot;
    2824    out[i].photcode   = in[i].photcode;
    2925    out[i].t          = in[i].t;
    3026    out[i].averef     = in[i].averef;
    31     out[i].dbFlags    = in[i].flags;
    3227    out[i].Xccd       = in[i].Xccd;
    3328    out[i].Yccd       = in[i].Yccd;
    3429    out[i].dXccd      = in[i].dXccd;
    3530    out[i].dYccd      = in[i].dYccd;
    36     out[i].stargal    = in[i].stargal;
    3731    out[i].Sky        = in[i].Sky;
    3832    out[i].dSky       = in[i].dSky;
    39     out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
     33
     34    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
     35    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
     36
     37    // changed or added for PS1_DEV_1 (2008.02.26)
     38    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
     39    out[i].dbFlags    = in[i].flags;
    4040    out[i].detID      = in[i].detID_lo;
    4141    out[i].imageID    = in[i].imageID_lo;
    42 
    43     // these don't have a correspondence
    44     out[i].psfChisq  = 0;
    45     out[i].crNsigma  = 0;
    46     out[i].extNsigma = 0;
    47     out[i].photFlags = 0;
     42    out[i].psfChisq   = 0;
     43    out[i].crNsigma   = 0;
     44    out[i].extNsigma  = 0;
     45
     46    // changed or added for PS1_DEV_2
     47    out[i].Map        = in[i].Mgal;
     48    out[i].dMcal      = 0;
     49
     50    // changed or added for PS1_V1
     51    out[i].photFlags  = in[i].dophot << 16;
     52    out[i].t_msec     = 0;
     53    out[i].extID      = 0;
     54    out[i].objID      = 0;
     55    out[i].catID      = 0;
     56    out[i].Mxx        = 0.0;
     57    out[i].Mxy        = 0.0;
     58    out[i].Myy        = 0.0;
     59    out[i].posangle   = 0;
     60    out[i].pltscale   = 0;
     61    out[i].psfNdof    = 0;
     62    out[i].psfNpix    = 0;
    4863  }
    4964  return (out);
     
    6479    out[i].dM         = in[i].dM;
    6580    out[i].Mcal       = in[i].Mcal;
    66     out[i].Mgal       = in[i].Map;
    6781    out[i].airmass    = in[i].airmass;
    6882    out[i].az         = in[i].az;
     
    7185    out[i].FWy        = in[i].FWy;
    7286    out[i].theta      = in[i].theta;
    73     out[i].dophot     = in[i].dophot;
    7487    out[i].photcode   = in[i].photcode;
    7588    out[i].t          = in[i].t;
    7689    out[i].averef     = in[i].averef;
    77     out[i].flags      = in[i].dbFlags;
    7890    out[i].Xccd       = in[i].Xccd;
    7991    out[i].Yccd       = in[i].Yccd;
    8092    out[i].dXccd      = in[i].dXccd;
    8193    out[i].dYccd      = in[i].dYccd;
    82     out[i].stargal    = in[i].stargal;
    8394    out[i].Sky        = in[i].Sky;
    8495    out[i].dSky       = in[i].dSky;
    85     out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
     96
     97    // changed or added for PS1_DEV_1 (2008.02.26)
     98    out[i].flags      = in[i].dbFlags;
     99    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
    86100    out[i].detID_hi   = 0;
    87101    out[i].detID_lo   = in[i].detID;
    88102    out[i].imageID_hi = 0;
    89103    out[i].imageID_lo = in[i].imageID;
     104
     105    // changed or added for PS1_DEV_2
     106    out[i].Mgal       = in[i].Map;
     107
     108    // changed or added for PS1_V1
     109    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
     110    out[i].dophot     = in[i].photFlags >> 16;
    90111  }
    91112  return (out);
     
    105126    out[i].D             = in[i].D;     
    106127    out[i].Xp            = in[i].Xp;     
    107     out[i].Nmeasure      = in[i].Nm;     
    108     out[i].Nmissing      = in[i].Nn;     
    109     out[i].code          = in[i].code;   
    110     out[i].measureOffset = in[i].offset;
    111     out[i].missingOffset = in[i].missing;
    112128    out[i].dR            = in[i].dR;
    113129    out[i].dD            = in[i].dD;
     
    120136    out[i].objID         = in[i].objID;
    121137    out[i].catID         = in[i].catID;
     138
     139    // changed or added for PS1_DEV_2
     140    out[i].Nmeasure      = in[i].Nm;     
     141    out[i].Nmissing      = in[i].Nn;     
     142    out[i].measureOffset = in[i].offset;
     143    out[i].missingOffset = in[i].missing;
     144    out[i].Nextend       = 0;
     145    out[i].extendOffset  = 0;
     146
     147    // changed or added for PS1_V1
     148    out[i].flags         = in[i].code;   
     149    out[i].ChiSq         = 0.0;
     150    out[i].Npos          = 0.0;
     151    out[i].extID         = 0;
    122152  }
    123153  return (out);
     
    137167    out[i].D        = in[i].D;     
    138168    out[i].Xp       = in[i].Xp;     
    139     out[i].Nm       = in[i].Nmeasure;     
    140     out[i].Nn       = in[i].Nmissing;     
    141     out[i].code     = in[i].code;   
    142     out[i].offset   = in[i].measureOffset;
    143     out[i].missing  = in[i].missingOffset;
    144169    out[i].dR       = in[i].dR;
    145170    out[i].dD       = in[i].dD;
     
    152177    out[i].objID    = in[i].objID;
    153178    out[i].catID    = in[i].catID;
     179
     180    // changed or added for PS1_DEV_2
     181    out[i].Nm       = in[i].Nmeasure;     
     182    out[i].Nn       = in[i].Nmissing;     
     183    out[i].offset   = in[i].measureOffset;
     184    out[i].missing  = in[i].missingOffset;
     185
     186    // changed or added for PS1_V1
     187    out[i].code          = in[i].flags;   
    154188  }
    155189  return (out);
     
    170204    out[i].Ncode = in[i].Ncode;
    171205    out[i].Nused = in[i].Nused;
     206
     207    // changed or added for PS1_V1
     208    out[i].M_20  = 0;     
     209    out[i].M_80  = 0;     
    172210 }
    173211  return (out);
     
    226264    out[i].fwhm_y           = in[i].fwhm_y;
    227265    out[i].trate            = in[i].trate;
    228     out[i].code             = in[i].code;
    229266    out[i].ccdnum           = in[i].ccdnum;
    230     out[i].imageID          = in[i].imageID_lo;
    231267
    232268    out[i].order            = in[i].order;
     
    245281    out[i].Mxyyy            = in[i].Mxyyy;
    246282    out[i].Myyyy            = in[i].Myyyy;
     283
     284    // changed or added for PS1_DEV_1
     285    out[i].imageID          = in[i].imageID_lo;
     286
     287    // changed or added for PS1_DEV_2
     288    out[i].externID         = 0;
     289    out[i].sourceID         = 0;
     290
     291    // changed or added for PS1_V1
     292    out[i].flags            = in[i].code;
     293    out[i].parentID         = 0;
    247294  }
    248295  return (out);
     
    283330    out[i].fwhm_y           = in[i].fwhm_y;
    284331    out[i].trate            = in[i].trate;
    285     out[i].code             = in[i].code;
    286332    out[i].ccdnum           = in[i].ccdnum;
    287     out[i].imageID_hi       = 0;
    288     out[i].imageID_lo       = in[i].imageID;
    289333
    290334    out[i].order            = in[i].order;
     
    303347    out[i].Mxyyy            = in[i].Mxyyy;
    304348    out[i].Myyyy            = in[i].Myyyy;
    305   }
    306   return (out);
    307 }
     349
     350    // changed or added for PS1_DEV_1
     351    out[i].imageID_hi       = 0;
     352    out[i].imageID_lo       = in[i].imageID;
     353
     354    // changed or added for PS1_V1
     355    out[i].code             = in[i].flags;
     356  }
     357  return (out);
     358}
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_convert_panstarrs_DEV_1.c

    r19185 r21536  
    1616    out[i].Mcal       = in[i].Mcal;
    1717
    18     // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
    19     // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
    20     out[i].Map        = in[i].Mgal;
    2118    out[i].airmass    = in[i].airmass;
    2219    out[i].az         = in[i].az;
     
    2522    out[i].FWy        = in[i].FWy;
    2623    out[i].theta      = in[i].theta;
    27     out[i].dophot     = in[i].dophot;
    2824    out[i].photcode   = in[i].photcode;
    2925    out[i].t          = in[i].t;
    3026    out[i].averef     = in[i].averef;
    31     out[i].dbFlags    = in[i].flags;
    3227    out[i].Xccd       = in[i].Xccd;
    3328    out[i].Yccd       = in[i].Yccd;
    3429    out[i].dXccd      = in[i].dXccd;
    3530    out[i].dYccd      = in[i].dYccd;
    36     out[i].stargal    = in[i].stargal;
    3731    out[i].Sky        = in[i].Sky;
    3832    out[i].dSky       = in[i].dSky;
    39     out[i].qPSF       = (in[i].qPSF == NAN_S_SHORT) ? NAN : in[i].qPSF;
     33
     34    // 2008.02.26 : I've renamed Mgal to Map, and intend it to be used per aperture
     35    // magnitudes.  Most uses of Mgal in the past were actually aperture (isophotal) mags
     36
     37    // changed or added for PS1_DEV_1 (2008.02.26)
     38    out[i].psfQual    = (in[i].psfQual == NAN_S_SHORT) ? NAN : in[i].psfQual;
     39    out[i].dbFlags    = in[i].flags;
    4040    out[i].detID      = in[i].detID_lo;
    4141    out[i].imageID    = in[i].imageID_lo;
    42 
    43     // these don't have a correspondence
    44     out[i].psfChisq  = 0;
    45     out[i].crNsigma  = 0;
    46     out[i].extNsigma = 0;
    47     out[i].photFlags = 0;
     42    out[i].psfChisq   = 0;
     43    out[i].crNsigma   = 0;
     44    out[i].extNsigma  = 0;
     45
     46    // changed or added for PS1_DEV_2
     47    out[i].Map        = in[i].Mgal;
     48    out[i].dMcal      = 0;
     49
     50    // changed or added for PS1_V1
     51    out[i].photFlags  = in[i].dophot << 16;
     52    out[i].t_msec     = 0;
     53    out[i].extID      = 0;
     54    out[i].objID      = 0;
     55    out[i].catID      = 0;
     56    out[i].Mxx        = 0.0;
     57    out[i].Mxy        = 0.0;
     58    out[i].Myy        = 0.0;
     59    out[i].posangle   = 0;
     60    out[i].pltscale   = 0;
     61    out[i].psfNdof    = 0;
     62    out[i].psfNpix    = 0;
    4863  }
    4964  return (out);
     
    6479    out[i].dM         = in[i].dM;
    6580    out[i].Mcal       = in[i].Mcal;
    66     out[i].Mgal       = in[i].Map;
    6781    out[i].airmass    = in[i].airmass;
    6882    out[i].az         = in[i].az;
     
    7185    out[i].FWy        = in[i].FWy;
    7286    out[i].theta      = in[i].theta;
    73     out[i].dophot     = in[i].dophot;
    7487    out[i].photcode   = in[i].photcode;
    7588    out[i].t          = in[i].t;
    7689    out[i].averef     = in[i].averef;
    77     out[i].flags      = in[i].dbFlags;
    7890    out[i].Xccd       = in[i].Xccd;
    7991    out[i].Yccd       = in[i].Yccd;
    8092    out[i].dXccd      = in[i].dXccd;
    8193    out[i].dYccd      = in[i].dYccd;
    82     out[i].stargal    = in[i].stargal;
    8394    out[i].Sky        = in[i].Sky;
    8495    out[i].dSky       = in[i].dSky;
    85     out[i].qPSF       = isnan(in[i].qPSF) ? NAN_S_SHORT : in[i].qPSF;
     96
     97    // changed or added for PS1_DEV_1 (2008.02.26)
     98    out[i].flags      = in[i].dbFlags;
     99    out[i].psfQual    = isnan(in[i].psfQual) ? NAN_S_SHORT : in[i].psfQual;
    86100    out[i].detID_hi   = 0;
    87101    out[i].detID_lo   = in[i].detID;
    88102    out[i].imageID_hi = 0;
    89103    out[i].imageID_lo = in[i].imageID;
     104
     105    // changed or added for PS1_DEV_2
     106    out[i].Mgal       = in[i].Map;
     107
     108    // changed or added for PS1_V1
     109    // out[i].photFlags  = in[i].photFlags & 0x0000ffff; (only dophot pre PS1_DEV_1)
     110    out[i].dophot     = in[i].photFlags >> 16;
    90111  }
    91112  return (out);
     
    105126    out[i].D             = in[i].D;     
    106127    out[i].Xp            = in[i].Xp;     
    107     out[i].Nmeasure      = in[i].Nm;     
    108     out[i].Nmissing      = in[i].Nn;     
    109     out[i].code          = in[i].code;   
    110     out[i].measureOffset = in[i].offset;
    111     out[i].missingOffset = in[i].missing;
    112128    out[i].dR            = in[i].dR;
    113129    out[i].dD            = in[i].dD;
     
    120136    out[i].objID         = in[i].objID;
    121137    out[i].catID         = in[i].catID;
     138
     139    // changed or added for PS1_DEV_2
     140    out[i].Nmeasure      = in[i].Nm;     
     141    out[i].Nmissing      = in[i].Nn;     
     142    out[i].measureOffset = in[i].offset;
     143    out[i].missingOffset = in[i].missing;
     144    out[i].Nextend       = 0;
     145    out[i].extendOffset  = 0;
     146
     147    // changed or added for PS1_V1
     148    out[i].flags         = in[i].code;   
     149    out[i].ChiSq         = 0.0;
     150    out[i].Npos          = 0.0;
     151    out[i].extID         = 0;
    122152  }
    123153  return (out);
     
    137167    out[i].D        = in[i].D;     
    138168    out[i].Xp       = in[i].Xp;     
    139     out[i].Nm       = in[i].Nmeasure;     
    140     out[i].Nn       = in[i].Nmissing;     
    141     out[i].code     = in[i].code;   
    142     out[i].offset   = in[i].measureOffset;
    143     out[i].missing  = in[i].missingOffset;
    144169    out[i].dR       = in[i].dR;
    145170    out[i].dD       = in[i].dD;
     
    152177    out[i].objID    = in[i].objID;
    153178    out[i].catID    = in[i].catID;
     179
     180    // changed or added for PS1_DEV_2
     181    out[i].Nm       = in[i].Nmeasure;     
     182    out[i].Nn       = in[i].Nmissing;     
     183    out[i].offset   = in[i].measureOffset;
     184    out[i].missing  = in[i].missingOffset;
     185
     186    // changed or added for PS1_V1
     187    out[i].code          = in[i].flags;   
    154188  }
    155189  return (out);
     
    170204    out[i].Ncode = in[i].Ncode;
    171205    out[i].Nused = in[i].Nused;
     206
     207    // changed or added for PS1_V1
     208    out[i].M_20  = 0;     
     209    out[i].M_80  = 0;     
    172210 }
    173211  return (out);
     
    226264    out[i].fwhm_y           = in[i].fwhm_y;
    227265    out[i].trate            = in[i].trate;
    228     out[i].code             = in[i].code;
    229266    out[i].ccdnum           = in[i].ccdnum;
    230     out[i].imageID          = in[i].imageID_lo;
    231267
    232268    out[i].order            = in[i].order;
     
    245281    out[i].Mxyyy            = in[i].Mxyyy;
    246282    out[i].Myyyy            = in[i].Myyyy;
     283
     284    // changed or added for PS1_DEV_1
     285    out[i].imageID          = in[i].imageID_lo;
     286
     287    // changed or added for PS1_DEV_2
     288    out[i].externID         = 0;
     289    out[i].sourceID         = 0;
     290
     291    // changed or added for PS1_V1
     292    out[i].flags            = in[i].code;
     293    out[i].parentID         = 0;
    247294  }
    248295  return (out);
     
    283330    out[i].fwhm_y           = in[i].fwhm_y;
    284331    out[i].trate            = in[i].trate;
    285     out[i].code             = in[i].code;
    286332    out[i].ccdnum           = in[i].ccdnum;
    287     out[i].imageID_hi       = 0;
    288     out[i].imageID_lo       = in[i].imageID;
    289333
    290334    out[i].order            = in[i].order;
     
    303347    out[i].Mxyyy            = in[i].Mxyyy;
    304348    out[i].Myyyy            = in[i].Myyyy;
    305   }
    306   return (out);
    307 }
     349
     350    // changed or added for PS1_DEV_1
     351    out[i].imageID_hi       = 0;
     352    out[i].imageID_lo       = in[i].imageID;
     353
     354    // changed or added for PS1_V1
     355    out[i].code             = in[i].flags;
     356  }
     357  return (out);
     358}
     359
     360// XXX no photcode conversions?  this may be from before we had a photcode FITS table...
     361
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_image.c

    r19185 r21536  
    196196  if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_2");
    197197  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_DEV_3");
     198  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_modify (&db[0].header, "FORMAT", "%s", 1, "PS1_V1");
    198199 
    199200  return;
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvo_image_raw.c

    r16810 r21536  
    5454  if (db[0].format == DVO_FORMAT_PS1_DEV_1)       ImageSize = sizeof(Image_PS1_DEV_1);
    5555  if (db[0].format == DVO_FORMAT_PS1_DEV_2)       ImageSize = sizeof(Image_PS1_DEV_2);
     56  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       ImageSize = sizeof(Image_PS1_DEV_3);
     57  if (db[0].format == DVO_FORMAT_PS1_V1)          ImageSize = sizeof(Image_PS1_V1);
    5658
    5759  /* check that filesize makes sense */
     
    7880  if (db[0].format == DVO_FORMAT_PS1_DEV_1)       gfits_table_mkheader_Image_PS1_DEV_1 (&db[0].theader);
    7981  if (db[0].format == DVO_FORMAT_PS1_DEV_2)       gfits_table_mkheader_Image_PS1_DEV_2 (&db[0].theader);
     82  if (db[0].format == DVO_FORMAT_PS1_DEV_3)       gfits_table_mkheader_Image_PS1_DEV_3 (&db[0].theader);
     83  if (db[0].format == DVO_FORMAT_PS1_V1)          gfits_table_mkheader_Image_PS1_V1 (&db[0].theader);
    8084   
    8185  /* read data from file */
  • branches/cnb_branch_20090215/Ohana/src/libdvo/src/dvosorts.c

    r16040 r21536  
    4646}
    4747
    48 void sort_stars_ra (Stars *stars, int N) {
    49 
    50 # define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
    51 # define COMPARE(A,B)(stars[A].R < stars[B].R)
    52 
    53   OHANA_SORT (N, COMPARE, SWAPFUNC);
    54 
    55 # undef SWAPFUNC
    56 # undef COMPARE
    57 
    58 }
    59 
    6048void sort_regions (SkyRegion *region, int N) {
    6149
     
    7058}
    7159
     60# if (0)
     61// deprecated along with Stars as an autocode type
     62void sort_stars_ra (Stars *stars, int N) {
     63
     64# define SWAPFUNC(A,B){ Stars tmp; tmp = stars[A]; stars[A] = stars[B]; stars[B] = tmp; }
     65# define COMPARE(A,B)(stars[A].R < stars[B].R)
     66
     67  OHANA_SORT (N, COMPARE, SWAPFUNC);
     68
     69# undef SWAPFUNC
     70# undef COMPARE
     71
     72}
     73# endif
  • branches/cnb_branch_20090215/Ohana/src/libohana/include/ohana.h

    r21153 r21536  
    66# include <time.h>
    77# include <stdlib.h>
     8# include <stdint.h>
    89# include <string.h>
    910# include <sys/socket.h>
  • branches/cnb_branch_20090215/Ohana/src/opihi/cmd.data/Makefile

    r17579 r21536  
    2020$(SRC)/accum.$(ARCH).o          \
    2121$(SRC)/applyfit2d.$(ARCH).o     \
    22 $(SRC)/applyfit.$(ARCH).o       \
     22$(SRC)/applyfit1d.$(ARCH).o     \
    2323$(SRC)/box.$(ARCH).o            \
    2424$(SRC)/book.$(ARCH).o           \
     
    2626$(SRC)/center.$(ARCH).o \
    2727$(SRC)/clear.$(ARCH).o          \
    28 $(SRC)/clip.$(ARCH).o           \
     28$(SRC)/imclip.$(ARCH).o         \
    2929$(SRC)/close.$(ARCH).o          \
    3030$(SRC)/concat.$(ARCH).o \
     
    4444$(SRC)/fft1d.$(ARCH).o          \
    4545$(SRC)/fft2d.$(ARCH).o          \
     46$(SRC)/fit1d.$(ARCH).o          \
    4647$(SRC)/fit2d.$(ARCH).o          \
    47 $(SRC)/fit.$(ARCH).o            \
    4848$(SRC)/gaussj.$(ARCH).o \
    4949$(SRC)/gaussdeviate.$(ARCH).o   \
     
    107107$(SRC)/spline_apply.$(ARCH).o   \
    108108$(SRC)/spline_construct.$(ARCH).o \
    109 $(SRC)/stats.$(ARCH).o             \
     109$(SRC)/imstats.$(ARCH).o           \
    110110$(SRC)/style.$(ARCH).o             \
    111111$(SRC)/subraster.$(ARCH).o         \
     
    131131$(SRC)/vroll.$(ARCH).o             \
    132132$(SRC)/vsmooth.$(ARCH).o        \
    133 $(SRC)/vstat.$(ARCH).o             \
     133$(SRC)/vstats.$(ARCH).o            \
    134134$(SRC)/wd.$(ARCH).o                \
    135135$(SRC)/write_vectors.$(ARCH).o     \
  • branches/cnb_branch_20090215/Ohana/src/opihi/cmd.data/init.c

    r21064 r21536  
    33int accum            PROTO((int, char **));
    44int applyfit         PROTO((int, char **));
     5int applyfit1d       PROTO((int, char **));
    56int applyfit2d       PROTO((int, char **));
    67int box              PROTO((int, char **));
     
    1112int clear            PROTO((int, char **));
    1213int clip             PROTO((int, char **));
     14int imclip           PROTO((int, char **));
    1315int close_device     PROTO((int, char **));
    1416int concat           PROTO((int, char **));
     
    2931int fft1d            PROTO((int, char **));
    3032int fft2d            PROTO((int, char **));
     33int fit              PROTO((int, char **));
     34int fit1d            PROTO((int, char **));
    3135int fit2d            PROTO((int, char **));
    32 int fit              PROTO((int, char **));
    3336int gaussjordan      PROTO((int, char **));
    3437int gaussdeviate     PROTO((int, char **));
     
    9295int spline_construct_cmd PROTO((int, char **));
    9396int stats            PROTO((int, char **));
     97int imstats          PROTO((int, char **));
    9498int style            PROTO((int, char **));
    9599int subraster        PROTO((int, char **));
     
    113117int vload            PROTO((int, char **));
    114118int vzload           PROTO((int, char **));
    115 int vstat            PROTO((int, char **));
     119int vstats           PROTO((int, char **));
    116120int vroll            PROTO((int, char **));
    117121int vpop             PROTO((int, char **));
     
    124128static Command cmds[] = { 
    125129  {1, "accum",        accum,            "accumulate vector values in another vector"},
    126   {1, "applyfit",     applyfit,         "apply fit to new vector"},
     130  {1, "applyfit",     applyfit1d,       "apply 1-d fit to new vector"},
     131  {1, "applyfit1d",   applyfit1d,       "apply 1-d fit to new vector"},
    127132  {1, "applyfit2d",   applyfit2d,       "apply 2-d fit to new vector"},
     133  {1, "book",         book_command,     "commands to manipulate book/page/word data"},
    128134  {1, "box",          box,              "draw a box on the plot"},
    129   {1, "book",         book_command,     "commands to manipulate book/page/word data"},
     135  {1, "buffers",      list_buffers,     "list the currently allocated buffers (images)"},
     136  {1, "images",       list_buffers,     "list the currently allocated images"},
    130137  {1, "center",       center,           "center image on coords"},
    131   {1, "parity",       parity,           "set image parity"},
    132138  {1, "circstats",    circstats,        "circular statistics"},
    133139  {1, "clear",        clear,            "erase plot"},
    134   {1, "clip",         clip,             "clip values in a buffer to be within a range"},
     140  {1, "clip",         imclip,           "clip values in an image to be within a range"},
    135141  {1, "close",        close_device,     "close the current display device"},
    136   {1, "concat",       concat,           "reduce vector dimension"},
     142  {1, "concat",       concat,           "append values to the end of a vector"},
    137143  {1, "contour",      contour,          "create contour from image"},
    138144  {1, "create",       create,           "create a new vector"},
     145  {1, "vcreate",      create,           "create a new vector"},
    139146  {1, "cumulative",   cumulative,       "build a cumulative histogram from a specific histogram"},
    140147  {1, "cursor",       cursor,           "get coords from cursor"},
     
    143150  {1, "dbconnect",    dbconnect,        "setup mysql db connection"},
    144151  {1, "dbselect",     dbselect,         "extract vectors from mysql database table"},
    145   {1, "delete",       delete,           "delete vectors or matrices"},
     152  {1, "delete",       delete,           "delete vectors or images"},
    146153  {1, "device",       device,           "set / get current graphics device"},
    147   {1, "dimendown",    dimendown,        "convert matrix to vector"},
    148   {1, "dimenup",      dimenup,          "convert vector to matrix"},
    149   {1, "erase",        erase,            "erase objects on an overlay"},
    150   {1, "extract",      extract,          "extract a portion of a buffer into another buffer"},
    151   {1, "fft1d",        fft1d,            "fft on the pixel-stream in an image"},
     154  {1, "dimendown",    dimendown,        "convert image to vector"},
     155  {1, "dimenup",      dimenup,          "convert vector to image"},
     156  {1, "dot",          dot,              "plot a single point"},
     157  {1, "erase",        erase,            "erase objects on an image overlay"},
     158  {1, "extract",      extract,          "extract a portion of a image into another image"},
     159  {1, "fft1d",        fft1d,            "fft on a vector"},
    152160  {1, "fft2d",        fft2d,            "fft on an image"},
    153   {1, "fit",          fit,              "fit polynomial to vector pair"},
     161  {1, "fit",          fit1d,            "fit polynomial to vector pair"},
     162  {1, "fit1d",        fit1d,            "fit polynomial to vector pair"},
    154163  {1, "fit2d",        fit2d,            "fit 2-d polynomial to vector triplet"},
    155   {1, "gaussj",       gaussjordan,      "solve Ax = B (N-D)"},
    156164  {1, "gaussdev",     gaussdeviate,     "generate a gaussian deviate vector"},
    157165  {1, "gaussint",     gaussintegral,    "return the integrated gaussian vector"},
    158   {1, "grid",         grid,             "plot cartesian grid"},
    159   {1, "gridify",      gridify,          "convert vector triplet to buffer"},
     166  {1, "gaussj",       gaussjordan,      "solve Ax = B (N-Dimensional)"},
     167  {1, "grid",         grid,             "plot cartesian grid on graph"},
     168  {1, "gridify",      gridify,          "convert vector triplet to image (same as vgrid?)"},
    160169  {1, "grow",         grow,             "grow a mask"},
    161   {1, "ungridify",    ungridify,        "convert buffer region to vector triplet"},
    162   {1, "header",       header,           "print buffer header"},
     170  {1, "header",       header,           "print image header"},
    163171  {1, "histogram",    histogram,        "generate histogram from vector"},
     172  {1, "imbin",        rebin,            "rebin image data by factor of N"},
     173  {1, "imclip",       imclip,           "clip values in an image to be within a range"},
    164174  {1, "imcut",        imcut,            "linear image cut between arbitrary coords"},
    165   {1, "imhist",       imhist,           "histogram of an image region"},
     175  {1, "imhistogram",  imhist,           "histogram of an image region"},
    166176  {1, "imsmooth",     imsmooth,         "circular gaussian smoothing"},
     177  {1, "imstats",      imstats,          "statistics on a portion of an image"},
    167178  {1, "integrate",    integrate,        "integrate a vector"},
    168179  {1, "interpolate",  interpolate,      "interpolate between vector pairs"},
    169   {1, "jpeg",         jpeg,             "write text line on graph"},
    170   {1, "png",          jpeg,             "write text line on graph"},
    171   {1, "ppm",          jpeg,             "write text line on graph"},
     180  {1, "jpeg",         jpeg,             "convert display image to JPEG"},
    172181  {1, "kern",         kern,             "convolve with 3x3 kernel"},
    173   {1, "keyword",      keyword,          "extract a FITS keyword from buffer header"},
     182  {1, "keyword",      keyword,          "extract a FITS keyword from image header"},
    174183  {1, "labels",       labels,           "define labels for plot"},
    175184  {1, "limits",       limits,           "define plot limits"},
    176   {1, "line",         line,             "plot line"},
    177   {1, "buffers",      list_buffers,     "list the currently allocated buffers"},
    178   {1, "vectors",      list_vectors,     "list vectors"},
    179   {1, "load",         load,             "load an SAOimage style overlay"},
     185  {1, "line",         line,             "plot a line"},
     186  {1, "load",         load,             "load an SAOimage/DS9 style overlay"},
    180187  {1, "lookup",       lookup,           "convert vector via lookup table (vector pair)"},
    181   {1, "mkrgb",        mkrgb,            "convert 3 images to rgb jpeg"},
    182   {1, "mcreate",      mcreate,          "create a matrix"},
     188  {1, "mcreate",      mcreate,          "create an image"},
     189  {1, "imcreate",     mcreate,          "create an image"},
    183190  {1, "medacc",       medacc,           "accumulate vector values in another vector"},
    184   {1, "mget",         mget,             "extract a vector from a matrix"},
     191  {1, "mget",         mget,             "extract a vector from an image"},
     192  {1, "imget",        mget,             "extract a vector from an image"},
    185193  {1, "minterp",      minterp,          "interpolate image pixels"},
    186   {1, "mset",         mset,             "insert a vector in a matrix"},
     194  {1, "iminterp",     minterp,          "interpolate image pixels"},
     195  {1, "mkrgb",        mkrgb,            "convert 3 images to rgb jpeg (use Kapa for better control)"},
     196  {1, "imset",        mset,             "insert a vector in an image"},
     197  {1, "parity",       parity,           "set image parity"},
    187198  {1, "peak",         peak,             "find vector peak in range"},
    188199  {1, "periodogram",  periodogram,      "measure periods in unevenly sampled data"},
    189200  {1, "plot",         plot,             "plot a pair of vectors"},
    190   {1, "dot",          dot,              "plot a single point"},
    191   {1, "point",        point,            "load overlay with single point"},
    192   {1, "ps",           ps,               "define labels for plot"},
     201  {1, "png",          jpeg,             "convert display graphic to PNG"},
     202  {1, "point",        point,            "load image overlay with a single point"},
     203  {1, "ppm",          jpeg,             "convert display graphic to PPM"},
     204  {1, "ps",           ps,               "convert display to PostScript"},
     205  {1, "queuedelete",  queuedelete,      "delete a queue"},
     206  {1, "queuedrop",    queuedrop,        "drop values from queue matching a key"},
     207  {1, "queueinit",    queueinit,        "create an empty queue"},
     208  {1, "queuelist",    queuelist,        "list defined queues"},
     209  {1, "queueload",    queueload,        "load queue from command"},
    193210  {1, "queuepop",     queuepop,         "pop value from queue to variable"},
    194   {1, "queuedrop",    queuedrop,        "drop values from queue matching a key"},
    195211  {1, "queueprint",   queueprint,       "print the contents of a queue"},
    196212  {1, "queuepush",    queuepush,        "push value onto queue"},
    197   {1, "queueinit",    queueinit,        "create an empty queue"},
    198   {1, "queuedelete",  queuedelete,      "delete a queue"},
    199   {1, "queuelist",    queuelist,        "list defined queues"},
    200   {1, "queueload",    queueload,        "load queue from command"},
     213  {1, "queuesize",    queuesize,        "show queue size"},
    201214  {1, "queuesubstr",  queuesubstr,      "bulk replace strings in queue"},
    202   {1, "queuesize",    queuesize,        "show queue size"},
    203215  {1, "rd",           rd,               "load fits image"},
    204216  {1, "rdseg",        rdseg,            "read a segment of an image from a file"},
    205217  {1, "read",         read_vectors,     "read vectors from datafile"},
    206   {1, "rebin",        rebin,            "rebin data by factor of N"},
     218  {1, "rebin",        rebin,            "rebin image data by factor of N"},
    207219  {1, "resize",       resize,           "set graphics/image window size"},
    208220  {1, "roll",         roll,             "roll image to new start point"},
    209221  {1, "rotate",       rotate,           "rotate image"},
    210   {1, "save",         save,             "save an SAOimage style overlay"},
     222  {1, "save",         save,             "save an SAOimage style image overlay"},
    211223  {1, "section",      section,          "define section of graph"},
    212   {1, "set",          set,              "vector math"},
     224  {1, "select",       vect_select,      "selective vector assignment"},
     225  {1, "set",          set,              "image and vector math"},
    213226  {1, "shift",        shift,            "shift data in an image"},
    214227  {1, "sort",         sort_vectors,     "sort list of vectors"},
    215228  {1, "spline.apply", spline_apply_cmd, "apply spline fit to generate an image"},
    216229  {1, "spline.const", spline_construct_cmd, "create spline 2nd deriv. terms"},
    217   {1, "stats",        stats,            "give statistics on a portion of a buffer"},
     230  {1, "stats",        imstats,          "statistics on a portion of an image"},
    218231  {1, "style",        style,            "set the style for graph plots"},
    219232  {1, "subraster",    subraster,        "subraster of fits image"},
    220   {1, "subset",       subset,           "expand vector dimension"},
    221   {1, "svd",          svd,              "singular value decomposition of a matrix"},
     233  {1, "subset",       subset,           "generate a vector from a portion of another vector"},
     234  {1, "svd",          svd,              "singular value decomposition of a matrix (image)"},
    222235  {1, "swapbytes",    swapbytes,        "byte swap thing"},
    223236  {1, "textline",     textline,         "write text line on graph"},
     
    225238  {1, "tvchannel",    tvchannel,        "set the current tv channel"},
    226239  {1, "tvcolors",     tvcolors,         "set the tv colormap"},
    227   {1, "tvcontour",    tvcontour,        "send contour to overlay"},
    228   {1, "tvgrid",       tvgrid,           "wait until return is typed"},
     240  {1, "tvcontour",    tvcontour,        "send contour to image overlay"},
     241  {1, "tvgrid",       tvgrid,           "RA/DEC grid on an image"},
     242  {1, "ungridify",    ungridify,        "convert image region to vector triplet"},
    229243  {1, "uniq",         uniq,             "create a uniq vector subset from a vector"},
    230244  {1, "unsign",       unsign,           "toggle the UNSIGN status"},
    231   {1, "vbin",         vbin,             "bin values in a vector to be within a range"},
     245  {1, "vbin",         vbin,             "rebin vector data by a fector of N"},
    232246  {1, "vclip",        vclip,            "clip values in a vector to be within a range"},
    233   {1, "select",       vect_select,      "selective vector assignment"},
    234   {1, "vgauss",       vgauss,           ""},
    235   {1, "vmaxwell",     vmaxwell,         ""},
    236   {1, "vgrid",        vgrid,            ""},
    237   {1, "vload",        vload,            "load vectors on Kii"},
    238   {1, "vzload",       vzload,           "load vectors on Kii"},
    239   {1, "vstat",        vstat,            "get info from imreg database"},
    240   {1, "vsmooth",      vsmooth,          "gaussian smooth of a vector"},
     247  {1, "vectors",      list_vectors,     "list vectors"},
     248  {1, "vgauss",       vgauss,           "fit a Gaussian to a vector"},
     249  {1, "vgrid",        vgrid,            "generate an image from a triplet of vectors"},
     250  {1, "vhistogram",   histogram,        "generate histogram from vector"},
     251  {1, "vload",        vload,            "load vectors as overlay on image display"},
     252  {1, "vmaxwell",     vmaxwell,         "fit a Maxwellian to a vector"},
     253  {1, "vpop",         vpop,             "remove first element of a vector"},
    241254  {1, "vroll",        vroll,            "roll vector elements"},
    242   {1, "vpop",         vpop,             "remove first element"},
     255  {1, "vsmooth",      vsmooth,          "Gaussian smooth of a vector"},
     256  {1, "vstats",       vstats,           "statistics on a vector"},
     257  {1, "vzload",       vzload,           "load vectors as overlay on image display (scaled points)"},
    243258  {1, "wd",           wd,               "write an image to a file"},
    244259  {1, "write",        write_vectors,    "write vectors to datafile"},
    245   {1, "zap",          zap,              "delete pixels"},
     260  {1, "zap",          zap,              "assign values to pixel regions"},
    246261  {1, "zplot",        zplot,            "plot x y with size scaled by z"},
    247262};
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/dbExtractAverages.c

    r21153 r21536  
    121121      break;
    122122    case AVE_FLAG:
    123       value.Int = average[0].code;
     123      value.Int = average[0].flags;
    124124      break;
    125125    case AVE_OBJID:
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/dbExtractImages.c

    r20936 r21536  
    247247      break;
    248248    case IMAGE_FLAG:
    249       value.Int = image[N].code;
     249      value.Int = image[N].flags;
    250250      break;
    251251    case IMAGE_CCDNUM:
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/dbExtractMeasures.c

    r21153 r21536  
    146146        case MAG_NPHOT:
    147147          if (equiv == NULL) {
    148             value.Int = NAN;
     148            value.Int = 0;
    149149            break;
    150150          }
     
    260260      break;
    261261    case MEAS_OBJFLAGS: /* OK */
    262       value.Int = average[0].code;
     262      value.Int = average[0].flags;
    263263      break;
    264264    // note that these represent the ra displacement relative to the average, not
     
    312312      break;
    313313    case MEAS_DOPHOT: /* OK */
    314       value.Flt = measure[0].dophot;
     314      value.Int = (measure[0].photFlags >> 16);
    315315      break;
    316316    case MEAS_DB_FLAGS: /* ? */
     
    394394      break;
    395395    case MEAS_PSF_QF: /* OK */
    396       value.Flt = measure[0].qPSF;
     396      value.Flt = measure[0].psfQual;
    397397      break;
    398398    case MEAS_PSF_CHISQ: /* OK */
     
    404404    case MEAS_EXT_NSIGMA: /* OK */
    405405      value.Flt = measure[0].extNsigma;
    406       break;
    407     case MEAS_STARGAL: /* OK */
    408       value.Flt = measure[0].stargal;
    409406      break;
    410407
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/dbFields.c

    r21153 r21536  
    170170  if (!strcasecmp (fieldName, "FWHM_MIN"))   ESCAPE (MEAS_FWHM_MIN,       MAG_NONE, OPIHI_FLT);
    171171  if (!strcasecmp (fieldName, "THETA"))      ESCAPE (MEAS_THETA,          MAG_NONE, OPIHI_FLT);
    172   if (!strcasecmp (fieldName, "DOPHOT"))     ESCAPE (MEAS_DOPHOT,         MAG_NONE, OPIHI_FLT);
     172  if (!strcasecmp (fieldName, "DOPHOT"))     ESCAPE (MEAS_DOPHOT,         MAG_NONE, OPIHI_INT);
    173173  if (!strcasecmp (fieldName, "DB_FLAGS"))   ESCAPE (MEAS_DB_FLAGS,       MAG_NONE, OPIHI_INT);
    174174  if (!strcasecmp (fieldName, "PHOT_FLAGS")) ESCAPE (MEAS_PHOT_FLAGS,     MAG_NONE, OPIHI_INT);
     
    193193  if (!strcasecmp (fieldName, "SKY"))        ESCAPE (MEAS_SKY,            MAG_NONE, OPIHI_FLT);
    194194  if (!strcasecmp (fieldName, "SKY_ERR"))    ESCAPE (MEAS_dSKY,           MAG_NONE, OPIHI_FLT);
    195   if (!strcasecmp (fieldName, "STARGAL"))    ESCAPE (MEAS_STARGAL,        MAG_NONE, OPIHI_FLT);
    196195
    197196  // for words that don't parse, try a photcode
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/gimages.c

    r21153 r21536  
    220220    if (PixelCoords) {
    221221      gprint (GP_LOG, "%3d %s %6.1f %6.1f %20s %5d %2d %4.2f %6.3f %5.3f %5.3f %4x\n",
    222                Nfound, image[i].name, X, Y, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].code);
     222               Nfound, image[i].name, X, Y, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].flags);
    223223    } else {
    224224      XY_to_RD (&ra, &dec, 0.5*image[i].NX, 0.5*image[i].NY, &image[i].coords);
    225225      gprint (GP_LOG, "%3d %s %8.4f %8.4f %20s %5d %2d %4.2f %6.3f %5.3f %5.3f %4x\n",
    226                Nfound, image[i].name, ra, dec, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].code);
     226               Nfound, image[i].name, ra, dec, date, image[i].nstar, image[i].photcode, image[i].secz, image[i].Mcal, image[i].dMcal, image[i].exptime, image[i].flags);
    227227    }
    228228    sprintf (name, "IMAGEx:%d", Nfound);
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/gstar.c

    r20936 r21536  
    158158        gprint (GP_LOG, "%3d   ",  catalog.average[k].Nmeasure);
    159159        gprint (GP_LOG, "%4.1f ",  0.01*catalog.average[k].Xp);
    160         gprint (GP_LOG, "%5d",     catalog.average[k].code);
     160        gprint (GP_LOG, "%5d",     catalog.average[k].flags);
    161161
    162162        if (FULL_OUTPUT) {
     
    211211            gprint (GP_LOG, "%7.4f ",  catalog.measure[m].dR);
    212212            gprint (GP_LOG, "%7.4f",   catalog.measure[m].dD);
    213             gprint (GP_LOG, "%2d ",    catalog.measure[m].dophot);
     213            gprint (GP_LOG, "%4x ",    catalog.measure[m].photFlags);
    214214            gprint (GP_LOG, "%3x ",    catalog.measure[m].dbFlags);
    215215            gprint (GP_LOG, "%5d ",    catalog.measure[m].photcode);
     
    233233                gprint (GP_LOG, "%d", catalog.measure[m].detID);
    234234                gprint (GP_LOG, "%d", catalog.measure[m].imageID);
    235                 gprint (GP_LOG, "%f", catalog.measure[m].qPSF);
     235                gprint (GP_LOG, "%f", catalog.measure[m].psfQual);
    236236                gprint (GP_LOG, "%f", catalog.measure[m].psfChisq);
    237237                gprint (GP_LOG, "%f", catalog.measure[m].crNsigma);
     
    240240                gprint (GP_LOG, "%f", 0.01*catalog.measure[m].FWy);
    241241                gprint (GP_LOG, "%f", (360.0/(float)0xffff)*catalog.measure[m].theta);
    242 
    243                 gprint (GP_LOG, "%x", catalog.measure[m].photFlags);
    244                 gprint (GP_LOG, "%d", catalog.measure[m].stargal);
    245242            }
    246243            gprint (GP_LOG, "\n");
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/paverage.c

    r20936 r21536  
    122122    /* project stars to screen display coords */
    123123    for (i = 0; (i < catalog.Naverage) && !interrupt; i++) {
    124       if (IDclip && (average[i].code != IDchoice)) continue;
     124      if (IDclip && (average[i].flags != IDchoice)) continue;
    125125      average[i].R = ohana_normalize_angle (average[i].R);
    126126      while (average[i].R < Rmin) average[i].R += 360.0;
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/photometry.c

    r17200 r21536  
    22
    33/* match code to measure  */
    4 # define TESTCODE(C,M) \
    5   if (C != NULL) { \
    6     switch (C[0].type) { \
    7     case PHOT_DEP: \
    8     case PHOT_REF: \
    9       if (C[0].code != M.photcode) continue; \
    10       break; \
    11     case PHOT_SEC: \
    12       if (C[0].code != GetPhotcodeEquivCodebyCode (M.photcode)) continue; \
    13       break; \
    14     default: \
    15       break; \
    16   } }
     4# define TESTCODE(C,M)                                                  \
     5  if (C != NULL) {                                                      \
     6    switch (C[0].type) {                                                \
     7      case PHOT_DEP:                                                    \
     8      case PHOT_REF:                                                    \
     9        if (C[0].code != M.photcode) continue;                          \
     10        break;                                                          \
     11      case PHOT_SEC:                                                    \
     12        if (C[0].code != GetPhotcodeEquivCodebyCode (M.photcode)) continue; \
     13        break;                                                          \
     14      default:                                                          \
     15        break;                                                          \
     16    } }
    1717
    1818/* exclusions based on measure.params  */
    19 # define TESTMEASURE(M) \
    20   if (ApplySelections[SelectionParam]) { \
    21     if (TimeSelect && (M.t < tzero)) continue; \
    22     if (TimeSelect && (M.t > tend)) continue; \
    23     if (ErrSelect  && (M.dM > ErrValue)) continue; \
     19# define TESTMEASURE(M)                                                 \
     20  if (ApplySelections[SelectionParam]) {                                \
     21    if (TimeSelect && (M.t < tzero)) continue;                          \
     22    if (TimeSelect && (M.t > tend)) continue;                           \
     23    if (ErrSelect  && (M.dM > ErrValue)) continue;                      \
     24    if (iMagSelect && (PhotInst (&M) < iMagMin)) continue;              \
     25    if (FlagSelect && (M.dbFlags != FlagValue)) continue;               \
    2426    if (TypeSelect && (TypeValue != GetMeasureTypeCode (&M))) continue; \
    25     if (iMagSelect && (PhotInst (&M) < iMagMin)) continue; \
    26     if (FlagSelect && (M.dbFlags != FlagValue)) continue; \
    27   }
    28 
    29 # define SETMAG(MOUT,MEAS,MODE) \
    30   MOUT = NAN; \
    31   if (MODE == MAG_INST) MOUT = PhotInst (&MEAS);  \
    32   if (MODE == MAG_CAT)  MOUT = PhotCat  (&MEAS); \
    33   if (MODE == MAG_SYS)  MOUT = PhotSys  (&MEAS, average, secfilt); \
    34   if (MODE == MAG_REL)  MOUT = PhotRel  (&MEAS, average, secfilt); \
     27  }
     28
     29# define SETMAG(MOUT,MEAS,MODE)                                         \
     30  MOUT = NAN;                                                           \
     31  if (MODE == MAG_INST) MOUT = PhotInst (&MEAS);                        \
     32  if (MODE == MAG_CAT)  MOUT = PhotCat  (&MEAS);                        \
     33  if (MODE == MAG_SYS)  MOUT = PhotSys  (&MEAS, average, secfilt);      \
     34  if (MODE == MAG_REL)  MOUT = PhotRel  (&MEAS, average, secfilt);      \
    3535  if (MODE == MAG_CAL)  MOUT = PhotCal  (&MEAS, average, secfilt, measure, GetPhotcodeEquivbyCode (MEAS.photcode)); \
    3636  if (MODE == MAG_AVE)  MOUT = PhotAve  (GetPhotcodeEquivbyCode (MEAS.photcode), average, secfilt); \
    3737  if (MODE == MAG_REF)  MOUT = PhotRef  (GetPhotcodeEquivbyCode (MEAS.photcode), average, secfilt, measure); \
    38   if (ApplySelections[SelectionParam]) { \
    39     if (MagSelect && (MOUT > MagMax)) continue; \
    40     if (MagSelect && (MOUT < MagMin)) continue; \
     38  if (ApplySelections[SelectionParam]) {                                \
     39    if (MagSelect && (MOUT > MagMax)) continue;                         \
     40    if (MagSelect && (MOUT < MagMin)) continue;                         \
    4141  }
    4242
     
    182182  if (!strcasecmp (parname, "dec"))      param = MEAS_DEC;
    183183  if (!strcasecmp (parname, "mag"))      param = MEAS_MAG;
    184   // if (!strcasecmp (parname, "dmag"))          param = MEAS_dMAG;
    185184  if (!strcasecmp (parname, "airmass"))  param = MEAS_AIRMASS;
    186185  if (!strcasecmp (parname, "exptime"))  param = MEAS_EXPTIME;
     
    190189  if (!strcasecmp (parname, "dD"))       param = MEAS_DEC_OFFSET;
    191190  if (!strcasecmp (parname, "fwhm"))     param = MEAS_FWHM;
    192   // if (!strcasecmp (parname, "dophot"))        param = MEAS_DOPHOT;
    193191  if (!strcasecmp (parname, "FLAGS"))    param = MEAS_DB_FLAGS;
    194192  if (!strcasecmp (parname, "XCCD"))     param = MEAS_XCCD;
     
    198196  if (!strcasecmp (parname, "help")) {
    199197    gprint (GP_ERR, "value may be one of the following:\n");
    200     gprint (GP_ERR, " ra dR dec dD mag dmag Mrel Mcal photcode time fwhm dophot xccd yccd xmosaic ymosaic flags\n");
     198    gprint (GP_ERR, " ra dR dec dD mag dmag Mrel Mcal photcode time fwhm xccd yccd xmosaic ymosaic flags\n");
    201199    gprint (GP_ERR, "value may also be a valid photcode\n");
    202200    gprint (GP_ERR, "photcodes or 'mag' may have optional magnitude type: mag,[Minst, Mcat, Msys, Mrel, Mcal]\n");
     
    311309
    312310  if (VarConfig ("ZERO_PT", "%lf", &ZERO_POINT) == (char *) NULL) {
    313       gprint (GP_ERR, "ZERO_PT undefined in config\n");
    314       return (FALSE);
     311    gprint (GP_ERR, "ZERO_PT undefined in config\n");
     312    return (FALSE);
    315313  }
    316314  SetZeroPoint (ZERO_POINT);
     
    324322
    325323  if (VarConfig ("PHOTCODE_FILE", "%s", MasterPhotcodeFile) == (char *) NULL) {
    326       gprint (GP_ERR, "PHOTCODE_FILE undefined in config\n");
    327       return (FALSE);
     324    gprint (GP_ERR, "PHOTCODE_FILE undefined in config\n");
     325    return (FALSE);
    328326  }
    329327  if (!LoadPhotcodes (CatdirPhotcodeFile, MasterPhotcodeFile)) {
     
    642640      break;
    643641    case AVE_FLAG:
    644       value = average[0].code;
     642      value = average[0].flags;
    645643      break;
    646644    case AVE_MAG:
     
    659657          value = NAN;
    660658          for (i = 0; i < average[0].Nmeasure; i++) {
    661               if (code[0].code != measure[i].photcode) continue;
    662               value = measure[i].M;
     659            if (code[0].code != measure[i].photcode) continue;
     660            value = measure[i].M;
    663661          }
    664662          break;
     
    675673      break;
    676674    case AVE_TYPEFRAC:
    677       value = DetermineTypefrac (average, measure, code);
     675      // value = DetermineTypefrac (average, measure, code);
     676      value = NAN;
    678677      break;
    679678    case AVE_NCODE:
     
    719718    if ((code != NULL) && (code[0].code != GetPhotcodeEquivCodebyCode (measure[k].photcode))) continue;
    720719    Nc ++;
    721     if (measure[k].dophot != TypefracType) continue;
     720    if ((measure[k].photFlags >> 16) != TypefracType) continue;
    722721    Nt ++;
    723722  }
     
    744743
    745744int GetMeasureTypeCode (Measure *measure) {
    746   switch (measure[0].dophot) {
     745  switch ((measure[0].photFlags >> 16)) {
    747746    case 0:
    748747    case 1:
     
    770769  if (IsDophot) {
    771770   
    772     if (measure[0].dophot == 4) return (FALSE);
     771    if ((measure[0].photFlags >> 16) == 4) return (FALSE);
    773772    return (TRUE);
    774773 
     
    866865  if (ErrSelect) {
    867866    dM = PhotdM (code, average, secfilt);
    868     if (dM > ErrValue) return (NAN);
     867    if (dM > ErrValue) return (FALSE);
    869868  }
    870869 
     
    11371136      value = average[0].D - measure[0].dD / 3600.0;
    11381137      break;
    1139 # if (0)
    1140     case MEAS_dMAG: /* OK */
    1141       value = measure[0].dM;
    1142       break;
    11431138    case MEAS_DOPHOT: /* OK */
    1144       value = measure[0].dophot;
    1145       break;
    1146 # endif
     1139      value = (measure[0].photFlags >> 16);
     1140      break;
    11471141    case MEAS_AIRMASS: /* OK */
    11481142      value = measure[0].airmass;
  • branches/cnb_branch_20090215/Ohana/src/opihi/dvo/pmeasure.c

    r20936 r21536  
    192192    /* project stars to screen display coords */
    193193    for (i = 0; (i < catalog.Naverage) && !interrupt; i++) {
    194       if (IDclip && (catalog.average[i].code != IDchoice)) continue;
     194      if (IDclip && (catalog.average[i].flags != IDchoice)) continue;
    195195      catalog.average[i].R = ohana_normalize_angle (catalog.average[i].R);
    196196      while (catalog.average[i].R < Rmin) catalog.average[i].R += 360.0;
  • branches/cnb_branch_20090215/Ohana/src/opihi/include/dvoshell.h

    r21153 r21536  
    106106      MEAS_CR_NSIGMA,
    107107      MEAS_EXT_NSIGMA,
    108       MEAS_STARGAL,
    109108};
    110109
  • branches/cnb_branch_20090215/Ohana/src/relastro/include/relastro.h

    r21153 r21536  
    6161  short Xm;
    6262  float secz;
    63   char code;
     63  char flags;
    6464  Coords coords;
    6565} Mosaic;
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/MosaicOps.c

    r16810 r21536  
    4747    mosaic[Nmosaic].dMcal = 0.0;
    4848    mosaic[Nmosaic].Xm    = 0.0;
    49     mosaic[Nmosaic].code  = image[i].code;
     49    mosaic[Nmosaic].flags  = image[i].flags;
    5050    mosaic[Nmosaic].secz  = image[i].secz;
    5151    mosaic[Nmosaic].coords = image[i].coords;
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/UpdateObjects.c

    r17419 r21536  
    169169      // position, consider including the lower-quality detections
    170170
    171       catalog[i].average[j].code &= ~ID_STAR_FEW;
     171      catalog[i].average[j].flags &= ~ID_STAR_FEW;
    172172
    173173      // XXX add the parallax factor range as a criterion as well
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/bcatalog.c

    r17212 r21536  
    3636      // XXX define astrometry vs photometry average.dbFlags
    3737      // XXX put photometry flags in secfilt (ie, per average mag?)
    38       subcatalog[0].average[Naverage].code &= ~ID_STAR_FEW;
    39       subcatalog[0].average[Naverage].code &= ~ID_STAR_POOR;
     38      subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW;
     39      subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR;
    4040    }
    4141
     
    7070
    7171      /* select measurements by quality */
    72       if (DophotSelect && (catalog[0].measure[offset].dophot != DophotValue)) continue;
     72      // XXX FIX THIS!!
     73      // if (DophotSelect && (catalog[0].measure[offset].dophot != DophotValue)) continue;
    7374
    7475      /* select measurements by quality */
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/load_catalogs.c

    r16810 r21536  
    3838      if (RESET) {
    3939        for (j = 0; j < catalog[i].Naverage; j++) {
    40           catalog[i].average[j].code = 0;
     40          catalog[i].average[j].flags = 0;
    4141          m = catalog[i].average[j].measureOffset;
    4242          for (k = 0; k < catalog[i].average[j].Nmeasure; k++) {
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/relastro_objects.c

    r17243 r21536  
    4040    if (RESET) {
    4141      for (j = 0; j < catalog.Naverage; j++) {
    42         catalog.average[j].code = 0;
     42        catalog.average[j].flags = 0;
    4343        m = catalog.average[j].measureOffset;
    4444        for (k = 0; k < catalog.average[j].Nmeasure; k++) {
  • branches/cnb_branch_20090215/Ohana/src/relastro/src/select_images.c

    r17205 r21536  
    147147      image[nimage] = timage[i];
    148148      /* always allow 'few' images to succeed, if possible */
    149       if (image[nimage].code & ID_IMAGE_FEW) {
    150         image[nimage].code &= ~(ID_IMAGE_FEW | ID_IMAGE_POOR);
     149      if (image[nimage].flags & ID_IMAGE_FEW) {
     150        image[nimage].flags &= ~(ID_IMAGE_FEW | ID_IMAGE_POOR);
    151151      }
    152152      if (RESET) {
     
    154154        assignMcal (&image[nimage], (double *) NULL, -1);
    155155        image[nimage].dMcal = NAN;
    156         image[nimage].code &= ~ID_IMAGE_POOR;
     156        image[nimage].flags &= ~ID_IMAGE_POOR;
    157157      }
    158158      line_number[nimage] = i;
  • branches/cnb_branch_20090215/Ohana/src/relphot/include/relphot.h

    r21153 r21536  
    2323  short Xm;
    2424  float secz;
    25   char code;
     25  char flags;
    2626  Coords coords;
    2727} Mosaic;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/GridOps.c

    r20936 r21536  
    369369
    370370      // skip stars marked as BAD
    371       if (catalog[c].average[n].code & STAR_BAD) {
     371      if (catalog[c].average[n].flags & STAR_BAD) {
    372372        Nrel ++;
    373373        continue;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/ImageOps.c

    r20936 r21536  
    244244  if (i == -1) return (NAN);
    245245
    246   if (image[i].code & IMAGE_BAD) return (NAN); 
     246  if (image[i].flags & IMAGE_BAD) return (NAN); 
    247247  value = image[i].Mcal;
    248248  return (value);
     
    285285    /* on PoorImages run, skip good images */
    286286    if (PoorImages) {
    287       bad = image[i].code & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
     287      bad = image[i].flags & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
    288288      if (!bad) continue;
    289289    }     
     
    331331      mark = (N < IMAGE_TOOFEW) || (N < IMAGE_GOOD_FRACTION*Nlist[i]);
    332332      if (mark) {
    333         image[i].code |= ID_IMAGE_FEW;
     333        image[i].flags |= ID_IMAGE_FEW;
    334334        Nfew ++;
    335335      } else {
    336         image[i].code &= ~ID_IMAGE_FEW;
     336        image[i].flags &= ~ID_IMAGE_FEW;
    337337      }     
    338338    }
     
    373373
    374374  for (i = N = 0; i < Nimage; i++) {
    375     if (image[i].code & IMAGE_BAD) continue;
     375    if (image[i].flags & IMAGE_BAD) continue;
    376376    mlist[N] = fabs (image[i].Mcal);
    377377    slist[N] = image[i].dMcal;
     
    390390  for (i = 0; i < Nimage; i++) {
    391391    mark = FALSE;
    392     image[i].code &= ~ID_IMAGE_POOR;
     392    image[i].flags &= ~ID_IMAGE_POOR;
    393393    mark = (image[i].dMcal > MaxScatter) || (fabs(image[i].Mcal - MedOffset) > MaxOffset);
    394394    if (mark) {
    395395      Nmark ++;
    396       image[i].code |= ID_IMAGE_POOR;
     396      image[i].flags |= ID_IMAGE_POOR;
    397397    } else {
    398       image[i].code &= ~ID_IMAGE_POOR;
     398      image[i].flags &= ~ID_IMAGE_POOR;
    399399    }
    400400  }
     
    470470  n = 0;
    471471  for (i = 0; i < Nimage; i++) {
    472     if (image[i].code & IMAGE_BAD)  continue;
     472    if (image[i].flags & IMAGE_BAD)  continue;
    473473
    474474    N = 0;
     
    512512  for (i = 0; i < Nimage; i++) {
    513513
    514     if (image[i].code & IMAGE_BAD)  continue;
     514    if (image[i].flags & IMAGE_BAD)  continue;
    515515
    516516    list[n] = pow (10.0, 0.01*image[i].Xm);
     
    540540  for (i = 0; i < Nimage; i++) {
    541541
    542     if (image[i].code & IMAGE_BAD)  continue;
     542    if (image[i].flags & IMAGE_BAD)  continue;
    543543
    544544    list[n] = image[i].Mcal;
     
    568568  for (i = 0; i < Nimage; i++) {
    569569
    570     if (image[i].code & IMAGE_BAD)  continue;
     570    if (image[i].flags & IMAGE_BAD)  continue;
    571571
    572572    list[n] = image[i].dMcal;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/MosaicOps.c

    r20323 r21536  
    6868    mosaic[Nmosaic].dMcal = 0.0;
    6969    mosaic[Nmosaic].Xm    = 0.0;
    70     mosaic[Nmosaic].code  = image[i].code;
     70    mosaic[Nmosaic].flags  = image[i].flags;
    7171    mosaic[Nmosaic].secz  = image[i].secz;
    7272
     
    183183      image[im].dMcal = mosaic[i].dMcal;
    184184      image[im].Xm = mosaic[i].Xm;
    185       image[im].code |= (mosaic[i].code & ID_IMAGE_FEW);
    186       image[im].code |= (mosaic[i].code & ID_IMAGE_POOR);
     185      image[im].flags |= (mosaic[i].flags & ID_IMAGE_FEW);
     186      image[im].flags |= (mosaic[i].flags & ID_IMAGE_POOR);
    187187    }
    188188  }     
     
    306306  if (i == -1) return (NAN);
    307307
    308   if (mosaic[i].code & IMAGE_BAD) return (NAN); 
     308  if (mosaic[i].flags & IMAGE_BAD) return (NAN); 
    309309  value = mosaic[i].Mcal;
    310310  return (value);
     
    343343    /* on PoorImages run, skip good images */
    344344    if (PoorImages) {
    345       bad = mosaic[i].code & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
     345      bad = mosaic[i].flags & (ID_IMAGE_FEW | ID_IMAGE_POOR | ID_IMAGE_SKIP);
    346346      if (!bad) continue;
    347347    }     
     
    393393      if (mark) {
    394394        fprintf (stderr, "marked image %s (%d), (%d < %d) || (%d < %f*%d)\n", image[imlist[i][0]].name, i, N, IMAGE_TOOFEW, N, IMAGE_GOOD_FRACTION, Nlist[i]);
    395         mosaic[i].code |= ID_IMAGE_FEW;
     395        mosaic[i].flags |= ID_IMAGE_FEW;
    396396        Nfew ++;
    397397      } else {
    398         mosaic[i].code &= ~ID_IMAGE_FEW;
     398        mosaic[i].flags &= ~ID_IMAGE_FEW;
    399399      }
    400400    }
     
    434434  n = 0;
    435435  for (i = 0; i < Nmosaic; i++) {
    436     if (mosaic[i].code & IMAGE_BAD) continue;
     436    if (mosaic[i].flags & IMAGE_BAD) continue;
    437437    list[n] = mosaic[i].Mcal;
    438438    dlist[n] = 1;
     
    462462  for (i = 0; i < Nmosaic; i++) {
    463463
    464     if (mosaic[i].code & IMAGE_BAD) continue;
     464    if (mosaic[i].flags & IMAGE_BAD) continue;
    465465    list[n] = mosaic[i].dMcal;
    466466    dlist[n] = 1;
     
    490490  n = 0;
    491491  for (i = 0; i < Nmosaic; i++) {
    492     if (mosaic[i].code & IMAGE_BAD)  continue;
     492    if (mosaic[i].flags & IMAGE_BAD)  continue;
    493493
    494494    N = 0;
     
    534534  for (i = 0; i < Nmosaic; i++) {
    535535
    536     if (mosaic[i].code & IMAGE_BAD) continue;
     536    if (mosaic[i].flags & IMAGE_BAD) continue;
    537537    list[n] = pow(10.0, 0.01*mosaic[i].Xm);
    538538    dlist[n] = 1;
     
    564564
    565565  for (i = N = 0; i < Nmosaic; i++) {
    566     if (mosaic[i].code & IMAGE_BAD) continue;
     566    if (mosaic[i].flags & IMAGE_BAD) continue;
    567567    mlist[N] = mosaic[i].Mcal;
    568568    slist[N] = mosaic[i].dMcal;
     
    584584    if (mark) {
    585585      Nmark ++;
    586       mosaic[i].code |= ID_IMAGE_POOR;
     586      mosaic[i].flags |= ID_IMAGE_POOR;
    587587    } else {
    588       mosaic[i].code &= ~ID_IMAGE_POOR;
     588      mosaic[i].flags &= ~ID_IMAGE_POOR;
    589589    }
    590590  }
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/StarOps.c

    r21153 r21536  
    2626
    2727  ave = catalog[cat].measure[meas].averef;
    28   if (catalog[cat].average[ave].code & STAR_BAD) return (NAN); 
     28  if (catalog[cat].average[ave].flags & STAR_BAD) return (NAN); 
    2929 
    3030  value = catalog[cat].secfilt[PhotNsec*ave+PhotSec].M;
     
    4444
    4545      /* calculate the average value for a single star */
    46       if (catalog[i].average[j].code & STAR_BAD) continue; 
     46      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    4747      m = catalog[i].average[j].measureOffset;
    4848
     
    8989
    9090      if (N <= STAR_TOOFEW) { /* too few measurements */
    91         catalog[i].average[j].code |= ID_STAR_FEW;
     91        catalog[i].average[j].flags |= ID_STAR_FEW;
    9292        Nfew ++;
    9393      } else {
    94         catalog[i].average[j].code &= ~ID_STAR_FEW;
     94        catalog[i].average[j].flags &= ~ID_STAR_FEW;
    9595      }
    9696
     
    208208
    209209          // XXX this is a hack for the 2MASS search; better to save an average value?
    210           if (catalog[i].measure[m].qPSF < 0.85) continue;
     210          if (catalog[i].measure[m].psfQual < 0.85) continue;
    211211
    212212          list[N] = Msys - catalog[i].measure[m].Mcal;
     
    280280  for (i = Ntot = 0; i < Ncatalog; i++) {
    281281    for (j = 0; j < catalog[i].Naverage; j++) {
    282       if (catalog[i].average[j].code & STAR_BAD) continue;
     282      if (catalog[i].average[j].flags & STAR_BAD) continue;
    283283      Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
    284284      if (Xm == -1) continue;
     
    306306      mark = (dM > MaxScatter) || (Xm == NAN_S_SHORT) || (Chisq > MaxChisq);
    307307      if (mark) {
    308         catalog[i].average[j].code |= ID_STAR_POOR;
     308        catalog[i].average[j].flags |= ID_STAR_POOR;
    309309        Ndel ++;
    310310      } else {
    311         catalog[i].average[j].code &= ~ID_STAR_POOR;
     311        catalog[i].average[j].flags &= ~ID_STAR_POOR;
    312312      }
    313313      Nave ++;
     
    351351
    352352      /* skip bad stars to prevent them from becoming good (on inner sample) */
    353       if (catalog[i].average[j].code & STAR_BAD) continue; 
     353      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    354354
    355355      /* on final processing, skip stars already measured */
     
    448448
    449449      /* calculate the average value for a single star */
    450       if (catalog[i].average[j].code & STAR_BAD) continue; 
     450      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    451451      m = catalog[i].average[j].measureOffset;
    452452
     
    493493
    494494      /* calculate the average value for a single star */
    495       if (catalog[i].average[j].code & STAR_BAD) continue; 
     495      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    496496
    497497      Xm = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
     
    529529
    530530      /* calculate the average value for a single star */
    531       if (catalog[i].average[j].code & STAR_BAD) continue; 
     531      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    532532
    533533      dM = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
     
    559559  for (i = 0; i < Ncatalog; i++) {
    560560    for (j = 0; j < catalog[i].Naverage; j++) {
    561       if (catalog[i].average[j].code & STAR_BAD) continue; 
     561      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    562562      dMrel = catalog[i].secfilt[PhotNsec*j+PhotSec].dM;
    563563      bin = dMrel / 0.00025;
     
    590590  for (i = 0; i < Ncatalog; i++) {
    591591    for (j = 0; j < catalog[i].Naverage; j++) {
    592       if (catalog[i].average[j].code & STAR_BAD) continue;
     592      if (catalog[i].average[j].flags & STAR_BAD) continue;
    593593      xlist[N] = catalog[i].secfilt[PhotNsec*j+PhotSec].M;
    594594      value    = catalog[i].secfilt[PhotNsec*j+PhotSec].Xm;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/bcatalog.c

    r20323 r21536  
    3434      subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].M  = NAN;
    3535      subcatalog[0].secfilt[PhotNsec*Naverage+PhotSec].dM = NAN;
    36       subcatalog[0].average[Naverage].code &= ~ID_STAR_FEW;
    37       subcatalog[0].average[Naverage].code &= ~ID_STAR_POOR;
     36      subcatalog[0].average[Naverage].flags &= ~ID_STAR_FEW;
     37      subcatalog[0].average[Naverage].flags &= ~ID_STAR_POOR;
    3838    }
    3939
     
    5555      /* select measurements by quality */
    5656      // XXX ignore this criterion for REF measurements?
    57       if (DophotSelect && (catalog[0].measure[offset].dophot != DophotValue)) continue;
     57      // XXX chnage this to select by bitflags
     58      if (DophotSelect && ((catalog[0].measure[offset].photFlags >> 16) != DophotValue)) continue;
    5859
    5960      /* select measurements by mag limit */
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/plot_scatter.c

    r20193 r21536  
    2323
    2424      /* calculate the average value for a single star */
    25       if (catalog[i].average[j].code & STAR_BAD) continue; 
     25      if (catalog[i].average[j].flags & STAR_BAD) continue; 
    2626      m = catalog[i].average[j].measureOffset;
    2727
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/relphot_objects.c

    r21153 r21536  
    4242      Nsecfilt = catalog.Nsecfilt;
    4343      for (j = 0; j < catalog.Naverage; j++) {
    44         catalog.average[j].code = 0;
     44        catalog.average[j].flags = 0;
    4545        for (k = 0; k < Nsecfilt; k++) {
    46           catalog.secfilt[j*Nsecfilt + k].M  = NAN;
    47           catalog.secfilt[j*Nsecfilt + k].dM = NAN;
    48           catalog.secfilt[j*Nsecfilt + k].Xm = NAN_S_SHORT;
     46          catalog.secfilt[j*Nsecfilt + k].M     = NAN;
     47          catalog.secfilt[j*Nsecfilt + k].M_20  = NAN_S_SHORT;
     48          catalog.secfilt[j*Nsecfilt + k].M_80  = NAN_S_SHORT;
     49          catalog.secfilt[j*Nsecfilt + k].dM    = NAN;
     50          catalog.secfilt[j*Nsecfilt + k].Xm    = NAN_S_SHORT;
    4951          catalog.secfilt[j*Nsecfilt + k].Ncode = 0;
    5052          catalog.secfilt[j*Nsecfilt + k].Nused = 0;
    51           catalog.secfilt[j*Nsecfilt + k].dummy = 0;
    5253        }
    5354        m = catalog.average[j].measureOffset;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/select_images.c

    r15509 r21536  
    133133      image[nimage] = timage[i];
    134134      /* always allow 'few' images to succeed, if possible */
    135       if (image[nimage].code & ID_IMAGE_FEW) {
    136         image[nimage].code &= ~(ID_IMAGE_FEW | ID_IMAGE_POOR);
     135      if (image[nimage].flags & ID_IMAGE_FEW) {
     136        image[nimage].flags &= ~(ID_IMAGE_FEW | ID_IMAGE_POOR);
    137137      }
    138138      if (RESET) {
    139139        assignMcal (&image[nimage], (double *) NULL, -1);
    140140        image[nimage].dMcal = NAN;
    141         image[nimage].code &= ~ID_IMAGE_POOR;
     141        image[nimage].flags &= ~ID_IMAGE_POOR;
    142142      }
    143143      line_number[nimage] = i;
  • branches/cnb_branch_20090215/Ohana/src/relphot/src/setMrelFinal.c

    r17201 r21536  
    5454  /* clear ID_STAR_POOR, ID_STAR_FEW, ID_MEAS_NOCAL values before writing ??? */
    5555  for (i = 0; i < catalog[0].Naverage; i++) {
    56     catalog[0].average[i].code &= ~ID_STAR_FEW;
    57     catalog[0].average[i].code &= ~ID_STAR_POOR;
     56    catalog[0].average[i].flags &= ~ID_STAR_FEW;
     57    catalog[0].average[i].flags &= ~ID_STAR_POOR;
    5858    m = catalog[0].average[i].measureOffset;
    5959    for (j = 0; j < catalog[0].average[i].Nmeasure; j++, m++) {
     
    102102
    103103      /* skip measurements with sat. dophot values */
    104       if ((pass < 4) && (catalog[0].measure[m].dophot == 10)) goto skip;
     104      // XXX we need to fix this: use the photFlags to ID saturation...
     105      // if ((pass < 4) && (catalog[0].measure[m].dophot == 10)) goto skip;
    105106
    106107      /* skip measurements from BAD images and mosaics */
     
    116117      }
    117118
    118       d1 = (catalog[0].measure[m].dophot == 1);
    119       d2 = (catalog[0].measure[m].dophot == 2);
     119      // d1 = (catalog[0].measure[m].dophot == 1);
     120      // d2 = (catalog[0].measure[m].dophot == 2);
     121      fprintf (stderr, "fix the dophot / type selections!");
     122      abort ();
    120123
    121124      /* skip measurements by measurement error */
  • branches/cnb_branch_20090215/Ohana/src/uniphot/src/find_image_sgroups.c

    r7080 r21536  
    2727  for (i = 0; i < Nimage; i++) {
    2828    if (imlink[i].sgroup != NULL) continue;
    29     if (image[i].code & ID_IMAGE_NOCAL) continue;
     29    if (image[i].flags & ID_IMAGE_NOCAL) continue;
    3030
    3131    /* new sgroup, set ref coords */
     
    5252
    5353    for (j = 0; j < Nimage; j++) {
    54       if (image[j].code & ID_IMAGE_NOCAL) continue;
     54      if (image[j].flags & ID_IMAGE_NOCAL) continue;
    5555      if (imlink[j].sgroup != NULL) continue;
    5656
  • branches/cnb_branch_20090215/Ohana/src/uniphot/src/find_image_tgroups.c

    r16040 r21536  
    6363      if (image[j].tzero < tmin[i]) continue;
    6464      if (image[j].tzero > tmax[i]) continue;
    65       if (image[j].code & ID_IMAGE_NOCAL) continue;
     65      if (image[j].flags & ID_IMAGE_NOCAL) continue;
    6666     
    6767      group[i].image[Nentry] = &image[j];
  • branches/cnb_branch_20090215/Ohana/src/uniphot/src/fit_groups.c

    r12332 r21536  
    1616  for (i = 0; i < Ntgroup; i++) {
    1717    for (j = Nlist = 0; j < tgroup[i].Nimage; j++) {
    18       if (tgroup[i].image[j][0].code & IMAGE_BAD) continue;
     18      if (tgroup[i].image[j][0].flags & IMAGE_BAD) continue;
    1919      sgroup = (Group *) tgroup[i].imlink[j][0].sgroup;
    2020      Mcal = tgroup[i].image[j][0].Mcal;
     
    5454  for (i = 0; i < Nsgroup; i++) {
    5555    for (j = Nlist = 0; j < sgroup[i].Nimage; j++) {
    56       if (sgroup[i].image[j][0].code & IMAGE_BAD) continue;
     56      if (sgroup[i].image[j][0].flags & IMAGE_BAD) continue;
    5757      tgroup = (Group *) sgroup[i].imlink[j][0].tgroup;
    5858      Mcal = sgroup[i].image[j][0].Mcal;
  • branches/cnb_branch_20090215/Ohana/src/uniphot/src/subset_images.c

    r12332 r21536  
    1616  for (i = 0; i < Nimage; i++) {
    1717     
    18     image[i].code |= ID_IMAGE_NOCAL;
     18    image[i].flags |= ID_IMAGE_NOCAL;
    1919
    2020    /* select images by photcode */
     
    2727      if (image[i].tzero > TSTOP) continue;
    2828    }
    29     image[i].code &= ~ID_IMAGE_NOCAL;
     29    image[i].flags &= ~ID_IMAGE_NOCAL;
    3030    keep[Nkeep] = i;
    3131    Nkeep ++;
  • branches/cnb_branch_20090215/Ohana/src/uniphot/src/update.c

    r19823 r21536  
    1616  /* clear the NOCAL flags */
    1717  for (i = 0; i < Nimage; i++) {
    18     image[i].code &= ~ID_IMAGE_NOCAL;
     18    image[i].flags &= ~ID_IMAGE_NOCAL;
    1919  }
    2020
  • branches/cnb_branch_20090215/ippTools/share/Makefile.am

    r20973 r21536  
    2121     chiptool_revertprocessedimfile.sql \
    2222     chiptool_run.sql \
     23     chiptool_export_run.sql \
     24     chiptool_export_imfiles.sql \
    2325     chiptool_unmasked.sql \
    2426     detselect_search.sql \
  • branches/cnb_branch_20090215/ippTools/src/chiptool.c

    r21463 r21536  
    5454static bool tofullimfileMode(pxConfig *config);
    5555static bool topurgedimfileMode(pxConfig *config);
     56static bool exportrunMode(pxConfig *config);
     57static bool importrunMode(pxConfig *config);
    5658
    5759# define MODECASE(caseName, func) \
     
    9193        MODECASE(CHIPTOOL_MODE_TOFULLIMFILE,            tofullimfileMode);
    9294        MODECASE(CHIPTOOL_MODE_TOPURGEDIMFILE,          topurgedimfileMode);
     95        MODECASE(CHIPTOOL_MODE_EXPORTRUN,               exportrunMode);
     96        MODECASE(CHIPTOOL_MODE_IMPORTRUN,               importrunMode);
    9397        default:
    9498            psAbort("invalid option (this should not happen)");
     
    880884}
    881885
    882 
    883886static bool pendingcleanupimfileMode(pxConfig *config)
    884887{
     
    10051008    return true;
    10061009}
    1007 
    10081010
    10091011static bool runMode(pxConfig *config)
     
    12511253    return change_imfile_data_state(config, "purged", "goto_purged");
    12521254}
     1255
     1256bool exportrunMode(pxConfig *config)
     1257{
     1258    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1259
     1260    PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", true,  false);
     1261    PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
     1262    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
     1263
     1264    FILE *f = fopen (outfile, "w");
     1265    if (f == NULL) {
     1266        psError(PS_ERR_UNKNOWN, false, "failed to open output file");
     1267        return false;
     1268    }
     1269
     1270    psMetadata *where = psMetadataAlloc();
     1271    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     1272
     1273    // *** extract the chipRun in this section ***
     1274    psString query = pxDataGet("chiptool_export_run.sql");
     1275    if (!query) {
     1276        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1277        return false;
     1278    }
     1279
     1280    if (where && psListLength(where->list)) {
     1281        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     1282        psStringAppend(&query, " %s", whereClause);
     1283        psFree(whereClause);
     1284    }
     1285
     1286    // treat limit == 0 as "no limit"
     1287    if (limit) {
     1288        psString limitString = psDBGenerateLimitSQL(limit);
     1289        psStringAppend(&query, " %s", limitString);
     1290        psFree(limitString);
     1291    }
     1292
     1293    if (!p_psDBRunQuery(config->dbh, query)) {
     1294        psError(PS_ERR_UNKNOWN, false, "database error");
     1295        psFree(query);
     1296        return false;
     1297    }
     1298    psFree(query);
     1299
     1300    psArray *output = p_psDBFetchResult(config->dbh);
     1301    if (!output) {
     1302        psError(PS_ERR_UNKNOWN, false, "database error");
     1303        return false;
     1304    }
     1305    if (!psArrayLength(output)) {
     1306        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1307        psFree(output);
     1308        return true;
     1309    }
     1310
     1311    // we must write the export table in non-simple (true) format
     1312    if (!ippdbPrintMetadatas(f, output, "chipRun", true)) {
     1313        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1314        psFree(output);
     1315        return false;
     1316    }
     1317    psFree(output);
     1318
     1319    // *** extract the chipProcessedImfile entries in this section ***
     1320    query = pxDataGet("chiptool_export_imfiles.sql");
     1321    if (!query) {
     1322        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1323        return false;
     1324    }
     1325
     1326    if (where && psListLength(where->list)) {
     1327        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     1328        psStringAppend(&query, " %s", whereClause);
     1329        psFree(whereClause);
     1330    }
     1331    psFree(where);
     1332
     1333    // treat limit == 0 as "no limit"
     1334    if (limit) {
     1335        psString limitString = psDBGenerateLimitSQL(limit);
     1336        psStringAppend(&query, " %s", limitString);
     1337        psFree(limitString);
     1338    }
     1339
     1340    if (!p_psDBRunQuery(config->dbh, query)) {
     1341        psError(PS_ERR_UNKNOWN, false, "database error");
     1342        psFree(query);
     1343        return false;
     1344    }
     1345    psFree(query);
     1346
     1347    output = p_psDBFetchResult(config->dbh);
     1348    if (!output) {
     1349        psError(PS_ERR_UNKNOWN, false, "database error");
     1350        return false;
     1351    }
     1352    if (!psArrayLength(output)) {
     1353        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1354        psFree(output);
     1355        return true;
     1356    }
     1357
     1358    // we must write the export table in non-simple (true) format
     1359    if (!ippdbPrintMetadatas(f, output, "chipProcessedImfiles", true)) {
     1360        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1361        psFree(output);
     1362        return false;
     1363    }
     1364    psFree(output);
     1365
     1366    fclose (f);
     1367
     1368    return true;
     1369}
     1370
     1371
     1372bool importrunMode(pxConfig *config)
     1373{
     1374  unsigned int nFail;
     1375
     1376  PS_ASSERT_PTR_NON_NULL(config, NULL);
     1377 
     1378  PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
     1379
     1380  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
     1381
     1382  fprintf (stdout, "---- input ----\n");
     1383  psMetadataPrint (stderr, input, 1);
     1384
     1385  psMetadataItem *chipRunItem = psMetadataLookup (input, "chipRun");
     1386  psAssert (chipRunItem, "entry not in input?");
     1387  psAssert (chipRunItem->type == PS_DATA_METADATA_MULTI, "entry not multi?");
     1388 
     1389  psMetadataItem *chipRunEntry = psListGet (chipRunItem->data.list, 0);
     1390  assert (chipRunEntry);
     1391  assert (chipRunEntry->type == PS_DATA_METADATA);
     1392  chipRunRow *chipRun = chipRunObjectFromMetadata (chipRunEntry->data.md);
     1393  chipRunInsertObject (config->dbh, chipRun);
     1394
     1395  // fprintf (stdout, "---- chip run ----\n");
     1396  // psMetadataPrint (stderr, chipRunEntry->data.md, 1);
     1397
     1398  psMetadataItem *item = psMetadataLookup (input, "chipProcessedImfiles");
     1399  psAssert (item, "entry not in input?");
     1400  psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
     1401
     1402  // XXX would be better to use the iterator?
     1403  for (int i = 0; i < item->data.list->n; i++) {
     1404    psMetadataItem *entry = psListGet (item->data.list, i);
     1405    assert (entry);
     1406    assert (entry->type == PS_DATA_METADATA);
     1407    chipProcessedImfileRow *chipProcessedImfile = chipProcessedImfileObjectFromMetadata (entry->data.md);
     1408    chipProcessedImfileInsertObject (config->dbh, chipProcessedImfile);
     1409
     1410    // fprintf (stdout, "---- row %d ----\n", i);
     1411    // psMetadataPrint (stderr, entry->data.md, 1);
     1412  }
     1413
     1414  return true;
     1415}
     1416
     1417
  • branches/cnb_branch_20090215/ippTools/src/chiptool.h

    r21463 r21536  
    4444    CHIPTOOL_MODE_TOCLEANEDIMFILE,
    4545    CHIPTOOL_MODE_TOFULLIMFILE,
    46     CHIPTOOL_MODE_TOPURGEDIMFILE
     46    CHIPTOOL_MODE_TOPURGEDIMFILE,
     47    CHIPTOOL_MODE_EXPORTRUN,
     48    CHIPTOOL_MODE_IMPORTRUN
    4749} chiptoolMode;
    4850
  • branches/cnb_branch_20090215/ippTools/src/chiptoolConfig.c

    r21463 r21536  
    244244    psMetadataAddStr(topurgedimfileArgs, PS_LIST_TAIL, "-class_id",  0,        "class ID to update", NULL);
    245245
     246    // -exportrun
     247    psMetadata *exportrunArgs = psMetadataAlloc();
     248    // pxchipSetSearchArgs (exportrunArgs); XXX include search terms?
     249    psMetadataAddS64(exportrunArgs, PS_LIST_TAIL, "-chip_id", 0,          "export this chip ID (required)", 0);
     250    psMetadataAddStr(exportrunArgs, PS_LIST_TAIL, "-outfile", 0,          "export to this file (required)", NULL);
     251    psMetadataAddU64(exportrunArgs, PS_LIST_TAIL, "-limit",   0,          "limit result set to N items", 0);
     252
     253    // -importrun
     254    psMetadata *importrunArgs = psMetadataAlloc();
     255    psMetadataAddStr(importrunArgs, PS_LIST_TAIL, "-infile",  0,          "import from this file (required)", NULL);
     256
    246257    psMetadata *argSets = psMetadataAlloc();
    247258    psMetadata *modes = psMetadataAlloc();
     
    264275    PXOPT_ADD_MODE("-run",                  "show runs",                            CHIPTOOL_MODE_RUN,                  runArgs);
    265276    PXOPT_ADD_MODE("-tocleanedimfile",      "set imfile state to cleaned",          CHIPTOOL_MODE_TOCLEANEDIMFILE,      tocleanedimfileArgs);
    266     PXOPT_ADD_MODE("-tofullimfile",        "set imfile state to full",              CHIPTOOL_MODE_TOFULLIMFILE,         tofullimfileArgs);
    267     PXOPT_ADD_MODE("-topurgedimfile",      "set imfile state to purged",            CHIPTOOL_MODE_TOPURGEDIMFILE,       topurgedimfileArgs);
     277    PXOPT_ADD_MODE("-tofullimfile",         "set imfile state to full",              CHIPTOOL_MODE_TOFULLIMFILE,         tofullimfileArgs);
     278    PXOPT_ADD_MODE("-topurgedimfile",       "set imfile state to purged",            CHIPTOOL_MODE_TOPURGEDIMFILE,       topurgedimfileArgs);
     279
     280    PXOPT_ADD_MODE("-exportrun",            "export run for import on other database", CHIPTOOL_MODE_EXPORTRUN, exportrunArgs);
     281    PXOPT_ADD_MODE("-importrun",            "import run from metadata file",           CHIPTOOL_MODE_IMPORTRUN, importrunArgs);
    268282
    269283    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • branches/cnb_branch_20090215/ippconfig/gpc1/Makefile.am

    r20199 r21536  
    1010        format_20080929.config \
    1111        format_20081011.config \
     12        format_20090120.config \
    1213        format_mef.config \
    1314        format_relphot.config \
  • branches/cnb_branch_20090215/ippconfig/gpc1/psphot.config

    r21057 r21536  
    33SAVE.OUTPUT     BOOL    TRUE
    44SAVE.BACKMDL    BOOL    TRUE
    5 #SAVE.RESID     BOOL    TRUE
    6 #SAVE.BACKGND   BOOL    TRUE
    7 #SAVE.BACKSUB   BOOL    TRUE
    8 #SAVE.PSF       BOOL    TRUE
    9 #LOAD.PSF       BOOL    FALSE
    10 #SAVE.PLOTS             BOOL    TRUE
     5SAVE.PSF        BOOL    TRUE
     6SAVE.PLOTS      BOOL    TRUE
    117
    128BACKGROUND.XBIN     S32  256            # size of background superpixels
     
    4238PSF.TREND.NY                        S32   1
    4339
    44 MOMENTS_SN_MIN      F32   30.0
     40MOMENTS_SN_MIN      F32   10.0
    4541EXT_MIN_SN           F32  50.0           # fit galaxies above this S/N limit
    4642FULL_FIT_SN_LIM      F32  50.0
    4743AP_MIN_SN            F32  50.0
    4844
    49 OUTPUT.FORMAT       STR PS1_DEV_1
     45OUTPUT.FORMAT        STR  PS1_V1
    5046
    5147PSF_SHAPE_NSIGMA     F32  3.0            # max significance for shape variation
  • branches/cnb_branch_20090215/ippconfig/recipes/fitstypes.mdc

    r17523 r21536  
    2424END
    2525DET_MASK        METADATA
    26         BITPIX          S32     8
     26        BITPIX          S32     16
    2727END
    2828DET_WEIGHT      METADATA
     
    3434END
    3535SKY_MASK        METADATA
    36         BITPIX          S32     8
     36        BITPIX          S32     16
    3737END
    3838SKY_WEIGHT      METADATA
     
    5454# Compressed mask
    5555COMP_MASK       METADATA
    56         BITPIX          S32     8
     56        BITPIX          S32     16
    5757        COMPRESSION     STR     PLIO
    5858        TILE.X          S32     0
  • branches/cnb_branch_20090215/ippconfig/recipes/psphot.config

    r21362 r21536  
    4949# parameters to control the selection of the peak in the Sx,Sy plane
    5050MOMENTS_SCALE                       F32   0.25       
    51 MOMENTS_SN_MIN                      F32   100.0           # min S/N to measure moments
     51MOMENTS_SN_MIN                      F32   10.0           # min S/N to measure moments
    5252MOMENTS_SX_MAX                      F32   50.0
    5353MOMENTS_SY_MAX                      F32   50.0
  • branches/cnb_branch_20090215/ippconfig/vysos5/camera.config

    r20102 r21536  
    33# File formats that we know about
    44FORMATS         METADATA
     5        FLIPPED STR     vysos5/format_flipped.config
    56        SIMPLE  STR     vysos5/format.config
    6         FLIPPED STR     vysos5/format_flipped.config
    77END
    88 
  • branches/cnb_branch_20090215/ippconfig/vysos5/format_flipped.config

    r20102 r21536  
    55        TELESCOP        STR     VYSOS-5
    66        INSTRUME        STR     Apogee USB/Net
     7        FLIPSTAT        STR     Flip/Mirror
    78END
    89
     
    6061        CELL.READDIR    S32     2
    6162        CELL.TIMESYS    STR     UTC
    62         CELL.XPARITY    S32     1
    63         CELL.YPARITY    S32     1
     63        CELL.XPARITY    S32     -1
     64        CELL.YPARITY    S32     -1
    6465        CHIP.XPARITY    S32     1
    6566        CHIP.YPARITY    S32     1
  • branches/cnb_branch_20090215/ippconfig/vysos5/psastro.config

    r20652 r21536  
    99# use plate-scale to make this in pixels?
    1010PSASTRO.GRID.OFFSET    F32     200.
    11 PSASTRO.GRID.SCALE     F32      50
     11PSASTRO.GRID.SCALE     F32      10
    1212PSASTRO.GRID.NSTAR.MAX S32     800 # max stars accepted for fitting
    1313
    14 PSASTRO.MAX.NRAW      S32      1000   # max stars accepted for fitting (0 for all)
    15 PSASTRO.MAX.NREF      S32      5000   # max stars accepted for fitting (0 for all)
     14PSASTRO.MAX.NRAW      S32       500   # max stars accepted for fitting (0 for all)
     15PSASTRO.MAX.NREF      S32      2000   # max stars accepted for fitting (0 for all)
    1616
    1717# extra field for ref stars:
  • branches/cnb_branch_20090215/ppImage/src/ppImageArguments.c

    r19943 r21536  
    8080    if ((argnum = psArgumentGet(argc, argv, "-visual"))) {
    8181        psArgumentRemove(argnum, &argc, argv);
    82         psphotSetVisual (true);
     82        pmVisualSetVisual(true);
    8383    }
    8484
     
    8686    if ((argnum = psArgumentGet(argc, argv, "-threads"))) {
    8787        psArgumentRemove(argnum, &argc, argv);
    88         int nThreads = atoi(argv[argnum]);
     88        int nThreads = atoi(argv[argnum]);
    8989        psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NTHREADS", 0, "number of warp threads", nThreads);
    9090        psArgumentRemove(argnum, &argc, argv);
    9191
    92         // create the thread pool with number of desired threads, supplying our thread launcher function
    93         // XXX need to determine the number of threads from the config data
    94         psThreadPoolInit (nThreads);
     92        // create the thread pool with number of desired threads, supplying our thread launcher function
     93        // XXX need to determine the number of threads from the config data
     94        psThreadPoolInit (nThreads);
    9595    }
    9696
  • branches/cnb_branch_20090215/ppStack/src/ppStack.c

    r21258 r21536  
    7474    pmConfigDone();
    7575    psLibFinalize();
    76 
     76    pmVisualClose();
    7777    exit(exitValue);
    7878}
  • branches/cnb_branch_20090215/ppStack/src/ppStackArguments.c

    r21477 r21536  
    176176    psMetadataAddF32(arguments, PS_LIST_TAIL, "-zp-star-limit", 0, "Limit on star rejection fraction for successful iteration", NAN);
    177177    psMetadataAddF32(arguments, PS_LIST_TAIL, "-zp-star-sys", 0, "Estimated systematic error", NAN);
    178     psMetadataAddBool(arguments, PS_LIST_TAIL, "-renorm", 0, "Renormalise variance maps?", false);
    179     psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-mean", 0,
    180                      "Statistic for mean in renormalisation", NULL);
    181     psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-stdev", 0,
    182                      "Statistic for stdev in renormalisation", NULL);
    183     psMetadataAddF32(arguments, PS_LIST_TAIL, "-renorm-width", 0, "Gaussian width for renormalisation", NAN);
    184     psMetadataAddS32(arguments, PS_LIST_TAIL, "-renorm-num", 0, "Number of samples for renormalisation", 0);
    185178    psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-image", 0, "Suffix for temporary images", NULL);
    186179    psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-mask", 0, "Suffix for temporary masks", NULL);
     
    189182                      "Delete temporary files on completion?", false);
    190183    psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads to use", 0);
    191     psMetadataAddBool(arguments, PS_LIST_TAIL, "-psphot-visual", 0, "psphot visualisation", 0);
     184    psMetadataAddBool(arguments, PS_LIST_TAIL, "-visual", 0, "visualisation", 0);
    192185
    193186    if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 3) {
     
    280273    }
    281274
    282     if (psMetadataLookupBool(NULL, arguments, "-renorm") ||
    283         psMetadataLookupBool(NULL, recipe, "RENORM")) {
    284         psMetadataAddBool(arguments, PS_LIST_TAIL, "RENORM", 0, "Renormalise variance maps?", true);
    285     }
    286     VALUE_ARG_RECIPE_INT("-renorm-num", "RENORM.NUM", S32, 0);
    287     VALUE_ARG_RECIPE_FLOAT("-renorm-width", "RENORM.WIDTH", F32);
    288     valueArgRecipeStr(arguments, recipe, "-renorm-mean",  "RENORM.MEAN", recipe);
    289     valueArgRecipeStr(arguments, recipe, "-renorm-stdev", "RENORM.STDEV", recipe);
    290 
    291275    valueArgRecipeStr(arguments, recipe, "-temp-image",    "TEMP.IMAGE",  recipe);
    292276    valueArgRecipeStr(arguments, recipe, "-temp-mask",     "TEMP.MASK",   recipe);
  • branches/cnb_branch_20090215/ppStack/src/ppStackLoop.c

    r21477 r21536  
    480480            psMetadataAddF32(stats, PS_LIST_TAIL, "STAMP.NUM", PS_META_DUPLICATE_OK,
    481481                             "Number of stamps", kernels->numStamps);
     482            float deconv = psMetadataLookupF32(NULL, readout->analysis,
     483                                               PM_SUBTRACTION_ANALYSIS_DECONV_MAX); // Deconvolution fraction
     484            psMetadataAddF32(stats, PS_LIST_TAIL, "KERNEL.DECONV", PS_META_DUPLICATE_OK,
     485                             "Deconvolution fraction for kernel", deconv);
    482486            psMetadataAddF32(stats, PS_LIST_TAIL, "PPSTACK.WEIGHTING", PS_META_DUPLICATE_OK,
    483487                             "Weighting for image", weightings->data.F32[i]);
     
    503507            psStringAppend(&name, "covariance_%d.fits", i);
    504508            writeImage(name, hdu->header, readout->covariance->image, config);
     509            pmStackVisualPlotTestImage(readout->covariance->image, name);
    505510            psFree(name);
    506511        }
     
    801806#ifdef TESTING
    802807    writeImage("combined_initial.fits", NULL, outRO->image, config);
     808    pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits");
    803809#endif
    804810
     
    884890                psString name = NULL;           // Name of image
    885891                psStringAppend(&name, "inspect_%03d.fits", i);
     892                pmStackVisualPlotTestImage(mask, name);
    886893                psFits *fits = psFitsOpen(name, "w");
    887894                psFree(name);
     
    901908                psString name = NULL;           // Name of image
    902909                psStringAppend(&name, "reject_%03d.fits", i);
     910                pmStackVisualPlotTestImage(mask, name);
    903911                psFits *fits = psFitsOpen(name, "w");
    904912                psFree(name);
     
    10341042
    10351043#ifdef TESTING
     1044    pmStackVisualPlotTestImage(outRO->image, "combined_initial.fits");
    10361045    writeImage("combined_final.fits", NULL, outRO->image, config);
    10371046#endif
     
    11511160    psLogMsg("ppStack", PS_LOG_INFO, "Stage 7 : WCS & JPEGS : %f sec", psTimerClear("PPSTACK_STEPS"));
    11521161
    1153     if (psMetadataLookupBool(&mdok, recipe, "RENORM")) {
    1154         // Statistics for renormalisation
    1155         psStatsOptions renormMean = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    1156                                                                                 "RENORM.MEAN"));
    1157         psStatsOptions renormStdev = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    1158                                                                                  "RENORM.STDEV"));
    1159         int renormNum = psMetadataLookupS32(&mdok, recipe, "RENORM.NUM"); // Number of samples
    1160         float renormWidth = psMetadataLookupS32(&mdok, recipe, "RENORM.WIDTH"); // Width of Gaussian phot
    1161         psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
    1162         if (!pmReadoutVarianceRenormPhot(outRO, maskValue, renormNum, renormWidth,
    1163                                          renormMean, renormStdev, NULL)) {
    1164             psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances.");
    1165             psFree(outRO);
    1166             return false;
    1167         }
    1168     }
    1169 
    1170     psLogMsg("ppStack", PS_LOG_INFO, "Stage 8 : Photometry Renormalization : %f sec", psTimerClear("PPSTACK_STEPS"));
    1171 
    11721162    if (psMetadataLookupBool(&mdok, recipe, "PHOTOMETRY")) {
    11731163        psTrace("ppStack", 1, "Photometering stacked image....\n");
     
    11991189    }
    12001190
    1201     psLogMsg("ppStack", PS_LOG_INFO, "Stage 9 : Photometry Analysis : %f sec", psTimerClear("PPSTACK_STEPS"));
     1191    psLogMsg("ppStack", PS_LOG_INFO, "Stage 8 : Photometry Analysis : %f sec", psTimerClear("PPSTACK_STEPS"));
    12021192
    12031193    psThreadPoolFinalize();
     
    12541244    }
    12551245
    1256     psLogMsg("ppStack", PS_LOG_INFO, "Stage 10 : Final Output : %f sec", psTimerClear("PPSTACK_STEPS"));
     1246    psLogMsg("ppStack", PS_LOG_INFO, "Stage 9 : Final Output : %f sec", psTimerClear("PPSTACK_STEPS"));
    12571247
    12581248    memDump("finish");
  • branches/cnb_branch_20090215/ppStack/src/ppStackMatch.c

    r21477 r21536  
    189189
    190190    bool mdok;                          // Status of MD lookup
    191     bool renorm = psMetadataLookupBool(&mdok, recipe, "RENORM"); // Renormalise variances?
    192191    float penalty = psMetadataLookupF32(NULL, ppsub, "PENALTY"); // Penalty for wideness
    193192    int threads = psMetadataLookupS32(NULL, config->arguments, "-threads"); // Number of threads
     
    359358                psString name = NULL;
    360359                psStringAppend(&name, "fake_%03d.fits", numInput);
     360                pmStackVisualPlotTestImage(fake->image, name);
    361361                psFits *fits = psFitsOpen(name, "w");
    362362                psFree(name);
     
    368368                psString name = NULL;
    369369                psStringAppend(&name, "real_%03d.fits", numInput);
     370                pmStackVisualPlotTestImage(readout->image, name);
    370371                psFits *fits = psFitsOpen(name, "w");
    371372                psFree(name);
     
    374375            }
    375376#endif
    376 
    377             // Renormalise the variances if desired
    378             if (renorm) {
    379                 // Statistics for renormalisation
    380                 psStatsOptions renormMean = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    381                                                                                         "RENORM.MEAN"));
    382                 psStatsOptions renormStdev = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    383                                                                                          "RENORM.STDEV"));
    384 
    385                 if (!pmReadoutVarianceRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) {
    386                     psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances.");
    387                     psFree(output);
    388                     return false;
    389                 }
    390             }
    391377
    392378            if (threads > 0) {
     
    413399                psString name = NULL;
    414400                psStringAppend(&name, "conv_%03d.fits", numInput);
     401                pmStackVisualPlotTestImage(output->image, name);
    415402                psFits *fits = psFitsOpen(name, "w");
    416403                psFree(name);
     
    422409                psString name = NULL;
    423410                psStringAppend(&name, "diff_%03d.fits", numInput);
     411                pmStackVisualPlotTestImage(fake->image, name);
    424412                psFits *fits = psFitsOpen(name, "w");
    425413                psFree(name);
     
    562550    }
    563551
    564     // Renormalise the variances if desired
    565     if (renorm) {
    566         // Statistics for renormalisation
    567         psStatsOptions renormMean = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    568                                                                                 "RENORM.MEAN"));
    569         psStatsOptions renormStdev = psStatsOptionFromString(psMetadataLookupStr(&mdok, recipe,
    570                                                                                  "RENORM.STDEV"));
    571 
    572         if (!pmReadoutVarianceRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) {
    573             psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances.");
    574             psFree(output);
    575             return false;
    576         }
    577     }
    578 
    579552    // Ensure the background value is zero
    580553    psStats *bg = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics for background
     
    664637        psString name = NULL;
    665638        psStringAppend(&name, "convolved_%03d.fits", numInput);
     639        pmStackVisualPlotTestImage(output->image, name);
    666640        psFits *fits = psFitsOpen(name, "w");
    667641        psFree(name);
  • branches/cnb_branch_20090215/ppStack/src/ppStackPhotometry.c

    r21259 r21536  
    118118    pmFPACopy(photFile->fpa, readout->parent->parent->parent);
    119119
    120     if (psMetadataLookupBool(NULL, config->arguments, "-psphot-visual")) {
    121         psphotSetVisual(true);
     120    if (psMetadataLookupBool(NULL, config->arguments, "-visual")) {
     121        pmVisualSetVisual(true);
    122122    }
    123123
  • branches/cnb_branch_20090215/ppStack/src/ppStackSources.c

    r21260 r21536  
    6969        psString name = NULL;
    7070        psStringAppend(&name, "start_%03d.fits", i);
     71        pmStackVisualPlotTestImage(fake->image, name);
    7172        psFits *fits = psFitsOpen(name, "w");
    7273        psFree(name);
     
    154155    int minMatches = PS_MAX (2, 0.5*num);
    155156    for (int i = 0; i < matches->n; i++) {
    156         pmSourceMatch *match = matches->data[i]; // Match of interest
    157         if (match->num < minMatches) continue;
    158 
    159         // We need to grab a single instance of this source: just take the first available
    160         int nImage = match->image->data.S32[0];
    161         int nIndex = match->index->data.S32[0];
    162         psArray *sources = sourceLists->data[nImage];
    163         pmSource *source = sources->data[nIndex];
    164        
    165         // stick this sample source on sourcesBest
    166         psArrayAdd (sourcesBest, 100, source);
     157        pmSourceMatch *match = matches->data[i]; // Match of interest
     158        if (match->num < minMatches) continue;
     159
     160        // We need to grab a single instance of this source: just take the first available
     161        int nImage = match->image->data.S32[0];
     162        int nIndex = match->index->data.S32[0];
     163        psArray *sources = sourceLists->data[nImage];
     164        pmSource *source = sources->data[nIndex];
     165
     166        // stick this sample source on sourcesBest
     167        psArrayAdd (sourcesBest, 100, source);
    167168    }
    168169    psMetadataAdd (sourcesCell->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY | PS_META_REPLACE, "psphot sources", sourcesBest);
  • branches/cnb_branch_20090215/ppSub/src/ppSub.c

    r21424 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:26:05 $
     8 *  @version $Revision: 1.11.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
    1221
    1322#include "ppSub.h"
     
    6675    psTimerStop();
    6776
    68     pmSubtractionVisualClose(); //close plot windows, if -visual is set
     77    pmVisualClose(); //close plot windows, if -visual is set
    6978    psFree(config);
    7079    pmModelClassCleanup();
  • branches/cnb_branch_20090215/ppSub/src/ppSub.h

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.6.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    1414#define PP_SUB_H
    1515
    16 #ifdef HAVE_CONFIG_H
    17 #include <config.h>
    18 #endif
    19 
    20 #include <stdio.h>
    21 #include <string.h>
    2216#include <pslib.h>
    2317#include <psmodules.h>
    24 #include <psphot.h>
    25 #include <ppStats.h>
    2618
    2719/// @addtogroup ppSub
     
    3224/// Setup the arguments parsing
    3325bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments
    34                         pmConfig *config    ///< Configuration
     26                        pmConfig *config    ///< Configuration
    3527    );
    3628
     
    5345    );
    5446
    55 /// generate (if needed) and set or update the masks for input and reference images
    56 bool ppSubSetMasks (pmConfig *config,     ///< Configuration
    57                     const pmFPAview *view ///< View of active readout
     47/// Generate (if needed) and set or update the masks for input and reference images
     48bool ppSubSetMasks(pmConfig *config,     ///< Configuration
     49                   const pmFPAview *view ///< View of active readout
    5850    );
    5951
    60 /// Generate the PSF-matching kernel and convolve the images as needed.  Most of this function
    61 /// involves looking up the parameters in the recipe and supplying them to the function
    62 /// pmSubtractionMatch()
    63 bool ppSubMatchPSFs (pmConfig *config,    ///< Configuration
    64                      const pmFPAview *view ///< View of active readout
     52/// Generate the PSF-matching kernel and convolve the images as needed.  Most of this function involves
     53/// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch()
     54bool ppSubMatchPSFs(pmConfig *config,    ///< Configuration
     55                    const pmFPAview *view ///< View of active readout
    6556    );
    6657
    67 /// generate the output readout and pass the kernel info to the header
    68 bool ppSubDefineOutput(pmConfig *config,          ///< Configuration
    69                        const pmFPAview *view ///< View of active readout
     58/// Generate the output readout and pass the kernel info to the header
     59bool ppSubDefineOutput(pmConfig *config, ///< Configuration
     60                       const pmFPAview *view ///< View of active readout
    7061    );
    7162
    72 /// Calculate the variance factor for the output image based on the input images
    73 bool ppSubVarianceFactors(pmConfig *config,       ///< Configuration
    74                           psMetadata *stats,    ///< Statistics, for output
    75                           const pmFPAview *view ///< View of active readout
    76     );
    77 
    78 /// Photometry stage 1: measure the PSF from the minuend image
    79 bool ppSubMakePSF(pmConfig *config,       ///< Configuration
    80                   const pmFPAview *view ///< View of active readout
     63/// Photometry stage 1: measure the PSF from the minuend image
     64bool ppSubMakePSF(pmConfig *config,       ///< Configuration
     65                  const pmFPAview *view ///< View of active readout
    8166    );
    8267
    8368/// Perform the actual image subtraction, update output concepts
    84 bool ppSubReadoutSubtract(pmConfig *config,       ///< Configuration
    85                           const pmFPAview *view ///< View of active readout
     69bool ppSubReadoutSubtract(pmConfig *config,       ///< Configuration
     70                          const pmFPAview *view ///< View of active readout
    8671    );
    8772
    8873
    8974/// Photometry stage 2: find and measure sources on the subtracted image
    90 bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
    91                             psMetadata *stats,    ///< Statistics, for output
    92                             const pmFPAview *view ///< View of active readout
     75bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
     76                            psMetadata *stats,    ///< Statistics, for output
     77                            const pmFPAview *view ///< View of active readout
    9378    );
    9479
    9580/// Renormalize, update headers and generate JPEGs
    96 bool ppSubReadoutUpdate(pmConfig *config,         ///< Configuration
    97                         const pmFPAview *view ///< View of active readout
     81bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration
     82                        psMetadata *stats, ///< Statistics for output, or NULL
     83                        const pmFPAview *view ///< View of active readout
    9884    );
    9985
     
    10793    );
    10894
    109 /// Generate and Set the masks if needed
    110 bool ppSubSetMasks (
    111     pmConfig *config,                   ///< Configuration
    112     const pmFPAview *view               ///< view to readout
    113     );
    114 
    115 /// Renormalize readout for peak pixels
    116 bool ppSubReadoutRenormPixels (
    117     pmConfig *config,                   ///< Configuration
    118     psMetadata *recipe,                         ///< Recipe
    119     pmReadout *readout                  ///< Readout
    120     );
    121 
    122 /// Renormalize readout for photometry analysis
    123 bool ppSubReadoutRenormPhot (
    124     pmConfig *config,                   ///< Configuration
    125     psMetadata *recipe,                         ///< Recipe
    126     pmReadout *readout                  ///< Readout
    127     );
    12895
    12996// Copy every instance of a single keyword from one metadata to another
  • branches/cnb_branch_20090215/ppSub/src/ppSubArguments.c

    r21424 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:26:05 $
     8 *  @version $Revision: 1.58.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
    1221
    1322#include "ppSub.h"
     
    191200    }
    192201
    193     if ((argnum = psArgumentGet(argc, argv, "-psphot-visual"))) {
    194         psArgumentRemove(argnum, &argc, argv);
    195         psphotSetVisual(true);
    196     }
    197202
    198203    pmConfigFileSetsMD(config->arguments, &argc, argv, "PPSUB.SOURCES", "-sources", NULL);
     
    240245    psMetadataAddS32(arguments, PS_LIST_TAIL, "-opt-order", 0, "Maximum order for optimum kernel search", -1);
    241246    psMetadataAddBool(arguments, PS_LIST_TAIL, "-dual", 0, "Dual convolution", false);
    242     psMetadataAddBool(arguments, PS_LIST_TAIL, "-renorm", 0, "Renormalise variance maps?", false);
    243     psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-mean", 0,
    244                      "Statistic for mean in renormalisation", NULL);
    245     psMetadataAddStr(arguments, PS_LIST_TAIL, "-renorm-stdev", 0,
    246                      "Statistic for stdev in renormalisation", NULL);
    247     psMetadataAddF32(arguments, PS_LIST_TAIL, "-renorm-width", 0, "Gaussian width for renormalisation", NAN);
    248     psMetadataAddS32(arguments, PS_LIST_TAIL, "-renorm-num", 0, "Number of samples for renormalisation", 0);
    249247    psMetadataAddBool(arguments, PS_LIST_TAIL, "-photometry", 0, "Perform photometry?", false);
    250248    psMetadataAddS32(arguments, PS_LIST_TAIL, "-threads", 0, "Number of threads", 0);
     
    352350                      psMetadataLookupBool(NULL, arguments, "-dual"));
    353351
    354     if (psMetadataLookupBool(NULL, arguments, "-renorm") ||
    355         psMetadataLookupBool(NULL, recipe, "RENORM")) {
    356         psMetadataAddBool(arguments, PS_LIST_TAIL, "RENORM", 0, "Renormalise variance maps?", true);
    357     }
    358     VALUE_ARG_RECIPE_INT("-renorm-num", "RENORM.NUM", S32, 0);
    359     VALUE_ARG_RECIPE_FLOAT("-renorm-width", "RENORM.WIDTH", F32);
    360     valueArgRecipeStr(arguments, recipe, "-renorm-mean", "RENORM.MEAN", recipe);
    361     valueArgRecipeStr(arguments, recipe, "-renorm-stdev", "RENORM.STDEV", recipe);
    362 
    363352    // Need to update this because it could have been overwritten by the camera's own recipe
    364353    if (psMetadataLookupBool(NULL, arguments, "-photometry")) {
     
    367356
    368357    if (psMetadataLookupBool(NULL, arguments, "-visual")) {
    369         pmSubtractionSetVisual(true);
     358        pmVisualSetVisual(true);
    370359    }
    371360
  • branches/cnb_branch_20090215/ppSub/src/ppSubBackground.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.6.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /**
    16  * Based on ppImageSubtractBackground()
    17  */
    1824bool ppSubBackground(pmConfig *config, const pmFPAview *view)
    1925{
    20     psAssert(config, "Need configuration");
    21     psAssert(view, "Need view to chip");
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    2228
    23     bool status; // Status of metadata lookups
     29    bool mdok; // Status of metadata lookups
    2430
    25     psMetadata *ppSubRecipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE);
     31    psMetadata *ppSubRecipe = psMetadataLookupPtr(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    2632    psAssert(ppSubRecipe, "Need PPSUB recipe");
    27 
    28     psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE);
     33    psMetadata *psphotRecipe = psMetadataLookupPtr(NULL, config->recipes, PSPHOT_RECIPE); // Recipe for psphot
    2934    psAssert(psphotRecipe, "Need PSPHOT recipe for binning");
    3035
    31     psImageMaskType maskBad = pmConfigMaskGet("BLANK", config);
     36    psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask
    3237
    33     // select the output readout
    34     pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
     38    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image
     39    pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL"); // Background model
    3540
    36     // select the model readout, if it exist already; if not, generate it
    37     pmReadout *modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
    38 
    39     // if necessary, generate the background model
     41    // Generate the background model, if required
    4042    if (!modelRO) {
    4143        // Create the background model
     
    4446            return false;
    4547        }
    46         // select the model readout (should now exist)
    47         modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
     48        // select the model readout (should now exist)
     49        modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
    4850        if (!modelRO) {
    4951            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find background model");
     
    5153        }
    5254    }
    53     psImageBinning *binning = psMetadataLookupPtr(&status, psphotRecipe,
     55    psImageBinning *binning = psMetadataLookupPtr(&mdok, psphotRecipe,
    5456                                                  "PSPHOT.BACKGROUND.BINNING"); // Binning for model
    5557    psImage *modelImage = modelRO->image; // Background model
    56 
    5758    psImage *image = outRO->image; // Image of interest
    5859    psImage *mask = outRO->mask; // Mask of interest
  • branches/cnb_branch_20090215/ppSub/src/ppSubCamera.c

    r21374 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 03:20:02 $
     8 *  @version $Revision: 1.33.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
    1221
    1322#include "ppSub.h"
     
    257266    // psPhot input
    258267    if (psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
    259         psphotModelClassInit ();        // load implementation-specific models
    260 
    261 
    262         // Internal-ish file for getting the PSF from the matched addition
     268        psphotModelClassInit();        // load implementation-specific models
     269
     270        // Internal-ish file for getting the PSF from the minuend
    263271        pmFPAfile *psf = pmFPAfileDefineOutputFromFile(config, output, "PSPHOT.PSF.LOAD");
    264272        if (!psf) {
     
    272280        pmFPAfileActivate(config->files, false, "PSPHOT.PSF.LOAD");
    273281
    274         pmFPAfile *psphotResid = pmFPAfileDefineOutputForFormat (config, NULL, "PSPHOT.RESID", output->cameraName, output->formatName);
    275         if (!psphotResid) {
    276             psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.RESID");
    277             return false;
    278         }
    279         // make this optional: psphotResid->save = true;
    280     }
    281 
    282     // Always do this, since we're using psphot for the background model.
    283     // XXX Not certain that I need to generate a separate pmFPAfile for PSPHOT.INPUT
    284     if (0) {
    285282        pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
    286283        if (!psphot) {
     
    297294            return false;
    298295        }
    299 
    300296    }
    301297
  • branches/cnb_branch_20090215/ppSub/src/ppSubDefineOutput.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20
    1321#include "ppSub.h"
    1422
    15 bool ppSubDefineOutput (pmConfig *config, const pmFPAview *view) {
     23bool ppSubDefineOutput(pmConfig *config, const pmFPAview *view)
     24{
     25    psAssert(config, "Require configuration");
     26    psAssert(view, "Require view");
    1627
    17     bool mdok;
    18 
    19     // generate an output readout
     28    // generate an output readout
    2029    pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT"); // Output cell
    2130    pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout: subtraction
     
    3039    pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference readout
    3140
    32     // Add kernel descrption to header.  We don't know which readout gets the kernels because
    33     // it depends on which is larger (the choice is set in ppSubMatchPSFs)
    34     bool inputHasKernel = true;
    35     pmSubtractionKernels *kernels = psMetadataLookupPtr(&mdok, inConv->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL); // Subtraction kernel
     41    // Add kernel descrption to header.
     42    // We don't know which readout has the kernels because it depends on which PSF is larger
     43    bool mdok;                          // Status of MD lookup
     44    psMetadata *analysis = inConv->analysis; // Analysis metadata with kernel information
     45    pmSubtractionKernels *kernels = psMetadataLookupPtr(&mdok, analysis,
     46                                                        PM_SUBTRACTION_ANALYSIS_KERNEL); // Subtraction kernel
    3647    if (!kernels) {
    37         kernels = psMetadataLookupPtr(&mdok, refConv->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL);
    38         inputHasKernel = false;
     48        analysis = refConv->analysis;
     49        kernels = psMetadataLookupPtr(&mdok, analysis, PM_SUBTRACTION_ANALYSIS_KERNEL);
    3950    }
    4051    if (!kernels) {
     
    4556        return false;
    4657    }
    47     psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.KERNEL", 0, "Subtraction kernel", kernels->description);
     58    psMetadataAddStr(outHDU->header, PS_LIST_TAIL, "PPSUB.KERNEL", 0, "Subtraction kernel",
     59                     kernels->description);
    4860
    49     if (inputHasKernel) {
    50         outRO->analysis = psMetadataCopy(outRO->analysis, inConv->analysis);
    51     } else {
    52         outRO->analysis = psMetadataCopy(outRO->analysis, refConv->analysis);
    53     }
     61    outRO->analysis = psMetadataCopy(outRO->analysis, analysis);
    5462
    5563#ifdef TESTING
    56     psImage *kernelImage = NULL;
    57 
    58     if (inputHasKernel) {
    59         kernelImage = psMetadataLookupPtr(&mdok, inConv->analysis, "SUBTRACTION.KERNEL.IMAGE"); // Image of the kernels
    60     } else {
    61         kernelImage = psMetadataLookupPtr(&mdok, refConv->analysis, "SUBTRACTION.KERNEL.IMAGE");
     64    {
     65        psImage *kernelImage = psMetadataLookupPtr(&mdok, analysis,
     66                                                   "SUBTRACTION.KERNEL.IMAGE"); // Image of kernel
     67        psFits *fits = psFitsOpen("kernel.fits", "w");
     68        psFitsWriteImage(fits, NULL, kernelImage, 0, NULL);
     69        psFitsClose(fits);
    6270    }
    63 
    64     psFits *fits = psFitsOpen("kernel.fits", "w");
    65     psFitsWriteImage(fits, NULL, kernelImage, 0, NULL);
    66     psFitsClose(fits);
    6771#endif
    6872
  • branches/cnb_branch_20090215/ppSub/src/ppSubLoop.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.23.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <pslib.h>
     18#include <psmodules.h>
     19#include <ppStats.h>
    1220
    1321#include "ppSub.h"
     
    138146                    return false;
    139147                }
    140                 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);
     148                psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);
    141149                ppStatsFPA(stats, output->fpa, view, maskValue, config);
    142150            }
  • branches/cnb_branch_20090215/ppSub/src/ppSubMakePSF.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /**
    16  * Photometry stage 1: measure the PSF from the minuend image
    17  */
    18 bool ppSubMakePSF (pmConfig *config, const pmFPAview *view) {
     24bool ppSubMakePSF(pmConfig *config, const pmFPAview *view)
     25{
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    1928
    20     bool mdok = false;
    21 
    22     // Photometry is to be performed in two stages:
    23     // 1. Measure the PSF using the PSF-matched images
    24     // 2. Find and measure sources on the subtracted image
    2529    psTimerStart("PPSUB_PHOT");
    2630
    27     // Look up recipe values
    2831    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    2932    psAssert(recipe, "We checked this earlier, so it should be here.");
    3033
    31     psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE); // Recipe for psphot
     34    if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) {
     35        return true;
     36    }
     37
     38    psMetadata *psphotRecipe = psMetadataLookupMetadata(NULL, config->recipes, PSPHOT_RECIPE);// psphot recipe
    3239    psAssert(recipe, "We checked this earlier, so it should be here.");
    33 
    34     if (!psMetadataLookupBool(NULL, recipe, "PHOTOMETRY")) return true;
    3540
    3641    bool reverse = psMetadataLookupBool(NULL, config->arguments, "REVERSE"); // Reverse sense of subtraction?
    3742
    38     pmReadout *minuend = NULL;
    39     pmFPAfile *minuendFile = NULL;
     43    bool mdok = false;                  // Status of MD lookup
     44    pmReadout *minuend = NULL;          // Image that will be positive following subtraction
     45    pmFPAfile *minuendFile = NULL;      // File for minuend image
    4046    if (reverse) {
    41         minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
    42         minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV");
     47        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
     48        minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.REF.CONV");
    4349    } else {
    44         minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV");
    45         minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV");
     50        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV");
     51        minuendFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT.CONV");
    4652    }
    4753
    48     // supply the minuend pmFPAfile to psphot as PSPHOT.INPUT:
    49     psMetadataAddPtr (config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot input : view on another pmFPAfile", minuendFile);
     54#if 1
     55    pmReadout *template = minuend;
     56    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     57    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
     58    if (!photRO) {
     59        pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer
     60        photRO = pmReadoutAlloc(cell); // Output readout: subtraction
     61    }
     62    photRO->image = psImageCopy(photRO->image, template->image, PS_TYPE_F32);
     63    if (template->variance) {
     64        photRO->variance = psImageCopy(photRO->variance, template->variance, PS_TYPE_F32);
     65    } else {
     66        psFree(photRO->variance);
     67        photRO->variance = NULL;
     68    }
     69    if (template->mask) {
     70        photRO->mask = psImageCopy(photRO->mask, template->mask, PS_TYPE_IMAGE_MASK);
     71    } else {
     72        psFree(photRO->mask);
     73        photRO->mask = NULL;
     74    }
     75#else
     76    // Supply the minuend pmFPAfile to psphot as PSPHOT.INPUT:
     77    psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
     78                     "psphot input: view on another pmFPAfile", minuendFile);
     79#endif
    5080
    51     // old-style variance renormalization
    52     if (!ppSubReadoutRenormPhot (config, recipe, minuend)) {
    53         psError(PS_ERR_UNKNOWN, false, "failure in renormalization");
    54         return false;
    55     }
    56 
    57     // extract the loaded sources from the associated readout
     81    // Extract the loaded sources from the associated readout, and generate PSF
     82    // Here, we assume the image is background-subtracted
    5883    pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES");
    5984    psArray *sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES");
    60 
    61     // generate PSF from the supplied sources (assumes image is background-subtracted)
    6285    if (!psphotReadoutFindPSF(config, view, sources)) {
    63         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");
    64         return false;
     86        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");
     87        return false;
    6588    }
    6689
     
    7093    psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MAJ");
    7194    psMetadataItemSupplement(hdu->header, psphotRecipe, "FWHM_MIN");
     95
     96    // Get rid of the generated header; it will be regenerated by the real photometry run
     97    psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER");
    7298
    7399    return true;
     
    87113
    88114// Blow away the sources psphot found --- they're irrelevant for the subtraction
    89 // XXX is this still needed?  These are now probably not being set 
     115// XXX is this still needed?  These are now probably not being set
    90116// pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with sources
    91117// psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
  • branches/cnb_branch_20090215/ppSub/src/ppSubMatchPSFs.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /** Generate the PSF-matching kernel and convolve the images as needed.  Most of this function
    16  * involves looking up the parameters in the recipe and supplying them to the function
    17  * pmSubtractionMatch();
    18  */
    19 
    20 bool ppSubMatchPSFs (pmConfig *config, const pmFPAview *view) {
    21 
    22     bool mdok;                          // Status of MD lookup
     24bool ppSubMatchPSFs(pmConfig *config, const pmFPAview *view)
     25{
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    2328
    2429    // Look up recipe values
     
    2631    psAssert(recipe, "We checked this earlier, so it should be here.");
    2732
    28     // input images
     33    // Input images
    2934    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT"); // Input readout
    3035    pmReadout *refRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF"); // Reference readout
    3136
    32     // get or generate output image holders
    33     pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved readout
     37    // Output image holders
     38    pmReadout *inConv = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved
    3439    if (!inConv) {
    35         pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Input convolved readout
    36         inConv = pmReadoutAlloc(cell); // Convolved version of input
     40        pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Cell for convolved input
     41        inConv = pmReadoutAlloc(cell);
    3742    }
    38     pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved readout
     43    pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved
    3944    if (!refConv) {
    40         pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Input convolved readout
    41         refConv = pmReadoutAlloc(cell); // Convolved version of input
     45        pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Cell for convolved ref.
     46        refConv = pmReadoutAlloc(cell);
    4247    }
    4348
    44     // options which control the generation of optimal parameters
    45     bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters?
    46     float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search
    47     float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search
    48     float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search
     49    bool mdok;                          // Status of MD lookup
    4950
    50     // Vector with FWHMs for optimum search
    51     psVector *optWidths = NULL;
    52     if (optimum) {
    53         optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32);
    54     }
    55 
    56     // Sources in image : these must be loaded from previous analysis stages
    57     pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); // Readout with sources
    58     psArray *sources = NULL;           
     51    // Sources in image, used for stamps: these must be loaded from previous analysis stages
     52    pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSUB.SOURCES"); // Readout with sources
     53    psArray *sources = NULL;            // Sources in image; used for stamps
    5954    if (sourcesRO) {
    6055        sources = psMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES");
     
    6661    float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing
    6762    float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps
    68 
    6963    const char *stampsName = psMetadataLookupStr(&mdok, config->arguments, "STAMPS"); // Filename for stamps
    7064
    7165    const char *typeStr = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE"); // Kernel type
    7266    psAssert(typeStr, "We put it here in ppSubArguments.c");
    73 
    7467    pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Type of kernel
    7568    if (type == PM_SUBTRACTION_KERNEL_NONE) {
     
    8780    int binning = psMetadataLookupS32(NULL, recipe, "SPAM.BINNING"); // Binning for SPAM kernel
    8881    float penalty = psMetadataLookupF32(NULL, recipe, "PENALTY"); // Penalty for wideness
    89 
    90     int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search
    91     float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search
    92 
    9382    int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations
    9483    float rej = psMetadataLookupF32(NULL, recipe, "REJ"); // Rejection threshold
     
    9887    float poorFrac = psMetadataLookupF32(&mdok, recipe, "POOR.FRACTION"); // Fraction for "poor"
    9988
    100     // XXX EAM : do we need to / want to define different values for BAD and POOR subtraction vs BAD and POOR warp?
    101     psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Bits to mask going in to pmSubtractionMatch
     89    // Options which control the generation of optimal parameters
     90    bool optimum = psMetadataLookupBool(&mdok, recipe, "OPTIMUM"); // Derive optimum parameters?
     91    float optMin = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MIN"); // Minimum width for search
     92    float optMax = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.MAX"); // Maximum width for search
     93    float optStep = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.STEP"); // Step for search
     94    psVector *optWidths = NULL;         // Vector with FWHMs for optimum search
     95    if (optimum) {
     96        optWidths = psVectorCreate(optWidths, optMin, optMax, optStep, PS_TYPE_F32);
     97    }
     98    int optOrder = psMetadataLookupS32(&mdok, recipe, "OPTIMUM.ORDER"); // Order for search
     99    float optThresh = psMetadataLookupF32(&mdok, recipe, "OPTIMUM.TOL"); // Tolerance for search
     100
     101    // XXX Do we need/want to define different values for BAD and POOR subtraction vs BAD and POOR warp?
     102    psImageMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Bits to mask in inputs
    102103    psImageMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config); // Bits to mask for poor pixels
    103104    psImageMaskType maskBad = pmConfigMaskGet("BLANK", config); // Bits to mask for bad pixels
     
    124125    pmSubtractionThreadsFinalize(inRO, refRO);
    125126
     127    psImageCovarianceTransfer(inConv->variance, inConv->covariance);
     128    psImageCovarianceTransfer(refConv->variance, refConv->covariance);
     129
    126130    // XXX drop the pixels associated with inRO and refRO (now that we have inConv and refConf)
    127131
  • branches/cnb_branch_20090215/ppSub/src/ppSubReadout.c

    r21424 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.112 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:26:05 $
     8 *  @version $Revision: 1.112.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
    1220
    1321#include "ppSub.h"
     
    1725    psTimerStart("PPSUB_MATCH");
    1826
    19     if (!ppSubSetMasks (config, view)) {
    20         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     27    if (!ppSubSetMasks(config, view)) {
     28        psError(PS_ERR_UNKNOWN, false, "Unable to set masks.");
    2129        return false;
    2230    }
    2331
    24     if (!ppSubMatchPSFs (config, view)) {
    25         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     32    if (!ppSubMatchPSFs(config, view)) {
     33        psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs.");
    2634        return false;
    2735    }
    2836
    29     if (!ppSubDefineOutput (config, view)) {
    30         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
    31         return false;
    32     }
    33 
    34     if (!ppSubVarianceFactors (config, stats, view)) {
    35         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     37    if (!ppSubDefineOutput(config, view)) {
     38        psError(PS_ERR_UNKNOWN, false, "Unable to define output.");
    3639        return false;
    3740    }
    3841
    3942    if (!ppSubMakePSF(config, view)) {
    40         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     43        psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
    4144        return false;
    4245    }
    4346
    44     if (!ppSubReadoutSubtract (config, view)) {
    45         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     47    if (!ppSubReadoutSubtract(config, view)) {
     48        psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
    4649        return false;
    4750    }
     
    5356    }
    5457
    55     if (!ppSubReadoutPhotometry (config, stats, view)) {
    56         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     58    if (!ppSubReadoutPhotometry(config, stats, view)) {
     59        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
    5760        return false;
    5861    }
    5962
    60     if (!ppSubReadoutUpdate (config, view)) {
    61         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     63    if (!ppSubReadoutUpdate(config, stats, view)) {
     64        psError(PS_ERR_UNKNOWN, false, "Unable to update.");
    6265        return false;
    6366    }
  • branches/cnb_branch_20090215/ppSub/src/ppSubReadoutPhotometry.c

    r21374 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 03:20:02 $
     8 *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /**
    16  * Photometry stage 2: find and measure sources on the subtracted image
    17  */
    18 bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view) {
    19 
    20     bool mdok = false;
     24bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view)
     25{
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    2128
    2229    // Look up recipe values
     
    3239    // The PSF (measured in ppSubMakePSF) is stored on the chip->analysis of PSPHOT.INPUT
    3340    // In order to use an incoming PSF, it must be stored on the chip->analysis of PSPHOT.PSF.LOAD
    34     pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT");
     41    pmChip *psfInputChip = pmFPAfileThisChip(config->files, view, "PSPHOT.INPUT"); // Chip with PSF
    3542    psAssert (psfInputChip, "should have been generated for ppSubMakePSF");
    36 
    37     pmChip *psfLoadChip = pmFPAfileThisChip(config->files, view, "PSPHOT.PSF.LOAD");
     43    pmChip *psfLoadChip = pmFPAfileThisChip(config->files, view, "PSPHOT.PSF.LOAD"); // Chip to have PSF
    3844    psAssert (psfLoadChip, "PSPHOT.PSF.LOAD should have been defined in ppSubCamera");
    39 
    40     pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF");
     45    pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); // PSF for photometry
    4146    if (!psf) {
    4247        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot");
    4348        return false;
    4449    }
    45     psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE, "PSF from matched addition", psf);
     50    psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,
     51                     "PSF from ppSubMakePSF", psf);
     52
     53    bool mdok = false;
    4654
    4755    // psphotReadoutMinimal performs the photometry analysis on PSPHOT.INPUT; we need to move
    4856    // around the pointers so PSPHOT.INPUT corresponds to the output image; previously, it was
    4957    // equivalent to the minuend image.
    50     pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT");
     58    pmFPAfile *outputFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
    5159    pmReadout *outRO = pmFPAviewThisReadout(view, outputFile->fpa); // Readout with the sources
    5260
    5361    // XXX possibly rename this to PPSUB.RESID?
    54     pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.RESID");
    55     pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
     62    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     63    pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout to photometer
    5664    if (!photRO) {
    57         pmCell *cell = pmFPAfileThisCell(config->files, view, "PSPHOT.RESID"); // Output cell
     65        pmCell *cell = pmFPAviewThisCell(view, photFile->fpa); // Cell to photometer
    5866        photRO = pmReadoutAlloc(cell); // Output readout: subtraction
    5967    }
     
    6270        photRO->variance = psImageCopy(photRO->variance, outRO->variance, PS_TYPE_F32);
    6371    } else {
    64         psFree (photRO->variance);
     72        psFree(photRO->variance);
    6573        photRO->variance = NULL;
    6674    }
     
    6876        photRO->mask = psImageCopy(photRO->mask, outRO->mask, PS_TYPE_IMAGE_MASK);
    6977    } else {
    70         psFree (photRO->mask);
     78        psFree(photRO->mask);
    7179        photRO->mask = NULL;
    7280    }
    7381
    74     // pmFPAfile *photFile = outputFile;
    75     psMetadataAddPtr (config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE, "psphot input : view on another pmFPAfile", photFile);
    76 
    77     // old-style variance renormalization
    78     if (!ppSubReadoutRenormPhot (config, recipe, photRO)) {
    79         psError(PS_ERR_UNKNOWN, false, "failure in renormalization");
    80         return false;
    81     }
     82#if 0
     83    psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
     84                     "psphot input: view on another pmFPAfile", photFile);
     85#endif
    8286
    8387    if (!psphotReadoutMinimal(config, view)) {
     
    8690        psErrorClear();
    8791    }
     92#if 1
     93    photRO->data_exists = true;
     94    photRO->parent->data_exists = true;
     95    photRO->parent->parent->data_exists = true;
     96#endif
    8897
    8998    if (stats) {
     
    101110}
    102111
    103     // XXX not sure that this is still needed (only if psphotReadoutMinimal measures the background)
    104     // if (!pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL") ||
    105     //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||
    106     //  !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {
    107     //  psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");
    108     //  return false;
    109     // }
    110112
    111     // pmFPAfileActivate(config->files, false, "PSPHOT.INPUT");
    112     // pmFPAfileActivate(config->files, false, "PSPHOT.LOAD.PSF");
     113
    113114
    114115
  • branches/cnb_branch_20090215/ppSub/src/ppSubReadoutSubtract.c

    r21424 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:26:05 $
     8 *  @version $Revision: 1.4.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:49 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20
    1321#include "ppSub.h"
     22
    1423#define WCS_TOLERANCE 0.001             // Tolerance for WCS
    1524
    16 bool ppSubReadoutSubtract (pmConfig *config, const pmFPAview *view) {
     25bool ppSubReadoutSubtract(pmConfig *config, const pmFPAview *view)
     26{
     27    psAssert(config, "Require configuration");
     28    psAssert(view, "Require view");
    1729
    18     bool mdok = false;
    1930
    2031    // Look up recipe values
    21     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     32    bool mdok = false;                  // Status of MD lookup
     33    psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSub
    2234    psAssert(recipe, "We checked this earlier, so it should be here.");
    2335
     
    2537
    2638    // Subtraction is: minuend - subtrahend
    27     pmReadout *minuend = NULL;
    28     pmReadout *subtrahend = NULL;
     39    pmReadout *minuend = NULL;          // Positive image
     40    pmReadout *subtrahend = NULL;       // Negative image
    2941    if (reverse) {
    3042        minuend = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV");
     
    5971    outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask);
    6072
     73    psArray *covars = psArrayAlloc(2);  // Covariance pseudo-matrices
     74    covars->data[0] = psMemIncrRefCounter(minuend->covariance);
     75    covars->data[1] = psMemIncrRefCounter(subtrahend->covariance);
     76    outRO->covariance = psImageCovarianceSum(covars);
     77    psFree(covars);
     78
    6179    outRO->data_exists = true;
    6280    outRO->parent->data_exists = true;
     
    6583    pmSubtractionVisualShowSubtraction(minuend->image, subtrahend->image, outRO->image);
    6684
    67     // copy concepts from the input to the output (XXX should this always use minuend?)
    68     pmFPAfile *inFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.INPUT");
    69     pmFPA *inFPA = inFile->fpa;
    70 
    71     pmFPAfile *outFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.OUTPUT");
    72     pmFPA *outFPA = outFile->fpa;
    73 
     85    // Copy concepts from the input to the output
     86    pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.INPUT"); // Input file
     87    pmFPA *inFPA = inFile->fpa;         // Input FPA
     88    pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
     89    pmFPA *outFPA = outFile->fpa;       // Output FPA
    7490    if (!pmFPACopyConcepts(outFPA, inFPA)) {
    7591        psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
     
    7894    }
    7995
    80     // get the HDUs and output Chip to copy the astrometry
    81     pmHDU *inHDU = inFPA->hdu;        // input HDU
    82     pmHDU *outHDU = outFPA->hdu;
    83     pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT");
    84 
     96    // Copy astrometry over
     97    // It should find its way into the output images and photometry
     98    pmHDU *inHDU = inFPA->hdu;          // Input HDU
     99    pmHDU *outHDU = outFPA->hdu;        // Output HDU
     100    pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip
    85101    if (!outHDU || !inHDU) {
    86102        psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry.");
    87103        return false;
    88104    }
    89 
    90     // Copy astrometry over
    91     // It should get into the output images and photometry
    92105    if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {
    93106        psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry from input FPA.");
    94107        return false;
    95108    }
    96 
    97109    if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    98110        psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to output FPA.");
     
    102114    return true;
    103115}
    104 
    105 // XXX this test code was in place to check for and squash unexpected NANs
    106 
    107 #if 0
    108     pmReadoutMaskApply(outRO, maskBad);
    109 
    110     for (int y = 0; y < outRO->image->numRows; y++) {
    111         for (int x = 0; x < outRO->image->numCols; x++) {
    112             if (isnan(outRO->image->data.F32[y][x]) && !(outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
    113                 printf("Unmasked NAN at %d %d --> %d\n", x, y, outRO->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x]);
    114             }
    115         }
    116     }
    117 #endif
    118 
  • branches/cnb_branch_20090215/ppSub/src/ppSubReadoutUpdate.c

    r21396 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-07 00:15:00 $
     8 *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20
    1321#include "ppSub.h"
    1422
    15 /**
    16  * Renormalize, update headers and generate JPEGs
    17  */
    18 bool ppSubReadoutUpdate (pmConfig *config, const pmFPAview *view) {
     23bool ppSubReadoutUpdate(pmConfig *config, psMetadata *stats, const pmFPAview *view)
     24{
     25    psAssert(config, "Require configuration");
     26    psAssert(view, "Require view");
    1927
    20     bool mdok = false;
     28    bool mdok = false;                  // Status of MD lookup
    2129
    2230    // Look up recipe values
     
    2432    psAssert(recipe, "We checked this earlier, so it should be here.");
    2533
    26     // select the output readout
    27     pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
    28 
    29     // Renormalising for pixels, because that's what magic desires
    30     if (!ppSubReadoutRenormPixels (config, recipe, outRO)) {
    31         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "failure in renormalization");
    32         return false;
    33     }
    34 
    35     // select the output FPA and HDU to get the output header
    36     pmFPAfile *outFile = psMetadataLookupPtr (&mdok, config->files, "PPSUB.OUTPUT");
    37     pmFPA *outFPA = outFile->fpa;
    38     pmHDU *outHDU = outFPA->hdu;
     34    pmFPAfile *outFile = psMetadataLookupPtr(&mdok, config->files, "PPSUB.OUTPUT"); // Output file
     35    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT"); // Output image
     36    pmFPA *outFPA = outFile->fpa;       // Output FPA
     37    pmHDU *outHDU = outFPA->hdu;        // Output HDU
    3938
    4039    // Add additional data to the header
     
    4645                     "Subtraction input", inFile->filename);
    4746
     47    // Statistics on the matching
     48    if (stats) {
     49        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);
     50        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);
     51        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);
     52        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);
     53        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);
     54        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);
     55        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);
     56        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);
     57        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);
     58        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);
     59        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);
     60
     61        psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
     62                         psTimerClear("PPSUB_MATCH"));
     63    }
     64
    4865    // Generate binned JPEGs
    4966    {
     
    5471
    5572        // Target cells
    56         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1");
    57         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2");
     73        pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG1"); // Rebinned cell once
     74        pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSUB.OUTPUT.JPEG2"); // Rebinned cell twice
    5875
    59         pmReadout *ro1 = pmReadoutAlloc(cell1);
    60         pmReadout *ro2 = pmReadoutAlloc(cell2); // Binned readouts
     76        pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    6177        if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) {
    6278            psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)");
  • branches/cnb_branch_20090215/ppSub/src/ppSubSetMasks.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
    1212
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <psphot.h>
     21
    1322#include "ppSub.h"
    1423
    15 /** this function generates (if needed) and sets or updates the masks for both the input and
    16  * reference images.  this function also has the code for interpolation over bad pixels, but it
    17  * is currently if-def-ed out
    18  */
     24bool ppSubSetMasks(pmConfig *config, const pmFPAview *view)
     25{
     26    psAssert(config, "Require configuration");
     27    psAssert(view, "Require view");
    1928
    20 bool ppSubSetMasks (pmConfig *config, const pmFPAview *view) {
    21 
    22     psImageMaskType maskValue;
    23     psImageMaskType markValue;
    24     bool mdok = false;
    25 
     29    psImageMaskType maskValue, markValue; // Mask values
    2630    if (!pmConfigMaskSetBits(&maskValue, &markValue, config)) {
    2731        psError(PS_ERR_UNKNOWN, false, "Unable to determine mask value.");
     
    2933    }
    3034
    31     // set the mask bits needed by psphot (in psphot recipe)
     35    // Set the mask bits needed by psphot (in psphot recipe)
    3236    psphotSetMaskRecipe (config, maskValue, markValue);
    3337
    3438    // Look up recipe values
    35     psMetadata *recipe = psMetadataLookupMetadata(&mdok, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     39    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    3640    psAssert(recipe, "We checked this earlier, so it should be here.");
    3741
    3842    psImageMaskType satValue = pmConfigMaskGet("SAT", config);
    39     psAssert (satValue, "SAT must be non-zero");
     43    psAssert(satValue, "SAT must be non-zero");
    4044
    4145    psImageMaskType badValue = pmConfigMaskGet("BAD", config);
    42     psAssert (badValue, "BAD must be non-zero");
     46    psAssert(badValue, "BAD must be non-zero");
    4347
    4448    // input images
     
    4953    psImage *reference = refRO->image;  // Reference image
    5054    PS_ASSERT_IMAGES_SIZE_EQUAL(input, reference, false);
    51 
    52     // XXX use psImageCopy below to avoid caring about image dimensions
    53     int numCols = input->numCols;
    54     int numRows = input->numRows;
     55    int numCols = input->numCols, numRows = input->numRows; // Size of image
    5556
    5657    // Generate masks if they don't exist
     
    7879    }
    7980    if (!pmReadoutMaskNonfinite(refRO, satValue)) {
    80         psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in reference.");
    81         return false;
     81        psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in reference.");
     82        return false;
    8283    }
    8384
    84 #if (0)
    85     // Look up recipe values
    86     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    87     psAssert(recipe, "We checked this earlier, so it should be here.");
    8885
     86#if 0
     87    // Interpolation over bad pixels: this takes a while!
    8988    bool mdok = false;
    90 
    9189    psString interpModeStr = psMetadataLookupStr(&mdok, recipe, "INTERPOLATION"); // Interpolation mode
    9290    psImageInterpolateMode interpMode = psImageInterpolateModeFromString(interpModeStr); // Interp
     
    102100    // Interpolate over bad pixels, so the bad pixels don't explode
    103101    if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    104         psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for input image.");
    105         return false;
     102        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for input image.");
     103        return false;
    106104    }
    107105    if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    108         psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for reference image.");
    109         return false;
     106        psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for reference image.");
     107        return false;
    110108    }
    111109    maskVal |= maskBad;
  • branches/cnb_branch_20090215/ppSub/src/ppSubVarianceFactors.c

    r21374 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 03:20:02 $
     8 *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    9696    vfItem->data.F32 = vf;
    9797
    98     // Statistics on the matching
    99     if (stats) {
    100         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);
    101         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);
    102         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);
    103         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);
    104         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);
    105         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);
    106         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);
    107         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);
    108         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);
    109         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);
    110         psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);
    111 
    112         psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
    113                          psTimerClear("PPSUB_MATCH"));
    114     }
    115 
    11698    return true;
    11799}
  • branches/cnb_branch_20090215/ppSub/src/ppSubVersion.c

    r21360 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 01:37:17 $
     8 *  @version $Revision: 1.3.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     12
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
     17#include <stdio.h>
     18#include <pslib.h>
     19#include <psmodules.h>
     20#include <ppStats.h>
    1221
    1322#include "ppSub.h"
  • branches/cnb_branch_20090215/psLib/m4

    • Property svn:ignore
      •  

        old new  
         1libtool.m4
         2ltoptions.m4
         3ltsugar.m4
         4ltversion.m4
         5lt~obsolete.m4
        16Makefile
        27Makefile.in
  • branches/cnb_branch_20090215/psLib/m4/.cvsignore

    r11609 r21536  
     1libtool.m4
     2ltoptions.m4
     3ltsugar.m4
     4ltversion.m4
     5lt~obsolete.m4
    16Makefile
    27Makefile.in
  • branches/cnb_branch_20090215/psLib/src/math/psPolynomialUtils.c

    r21183 r21536  
    139139// XXX determine the errors, and propagate to the output of psImageBicubeMin
    140140// XXX x,y are the image pixel index, but the fit is implied for the image pixel coordinates (0.5,0.5 center)
     141// this solution is determined assuming constant weight per pixel
    141142psPolynomial2D *psImageBicubeFit(const psImage *image, int x, int y)
    142143{
     
    179180psPlane psImageBicubeMin(const psPolynomial2D *poly)
    180181{
    181     psPlane min = { NAN, NAN, 0, 0 };   // Minimum value to return
     182    psPlane min = { NAN, NAN, NAN, NAN };   // Minimum value to return
    182183
    183184    PS_ASSERT_PTR_NON_NULL(poly, min);
     
    186187
    187188    double det = 4*poly->coeff[2][0]*poly->coeff[0][2] - PS_SQR(poly->coeff[1][1]); // Determinant
    188     min.x = (poly->coeff[1][1]*poly->coeff[0][1] - 2*poly->coeff[0][2]*poly->coeff[1][0]) / det;
    189     min.y = (poly->coeff[1][1]*poly->coeff[1][0] - 2*poly->coeff[2][0]*poly->coeff[0][1]) / det;
     189    double xn = (poly->coeff[1][1]*poly->coeff[0][1] - 2*poly->coeff[0][2]*poly->coeff[1][0]);
     190    double yn = (poly->coeff[1][1]*poly->coeff[1][0] - 2*poly->coeff[2][0]*poly->coeff[0][1]);
     191
     192    min.x = xn / det;
     193    min.y = yn / det;
     194
     195    // sigma_xn^2 / xn^2 = sigma_11^2 / C11
     196
     197    // without a supplied error, we calculate the normalized error
     198    double fdetErr2 = 0.5/PS_SQR(poly->coeff[0][2]) + 0.5/PS_SQR(poly->coeff[2][0]) + 4.0/(6.0*PS_SQR(poly->coeff[1][1]));
     199    double fxnErr2 = 1.0/(6.0*PS_SQR(poly->coeff[0][1])) + 1.0/(6.0*PS_SQR(poly->coeff[1][0])) + 1.0/(6.0*PS_SQR(poly->coeff[1][1])) + 0.5/PS_SQR(poly->coeff[0][2]);
     200    double fynErr2 = 1.0/(6.0*PS_SQR(poly->coeff[0][1])) + 1.0/(6.0*PS_SQR(poly->coeff[1][0])) + 1.0/(6.0*PS_SQR(poly->coeff[1][1])) + 0.5/PS_SQR(poly->coeff[2][0]);
     201
     202    min.xErr = fabs(min.x) * sqrt(fxnErr2 + fdetErr2);
     203    min.yErr = fabs(min.y) * sqrt(fynErr2 + fdetErr2);
    190204
    191205    return min;
  • branches/cnb_branch_20090215/psModules/src/astrom/pmAstrometryVisual.c

    r21422 r21536  
    2323
    2424//variables to determine when things are plotted
    25 static bool isVisual             = false;
    2625static bool plotGridMatch        = true;
    2726static bool plotTweak            = true;
     
    4847/* Initialization Routines  */
    4948
    50 bool pmAstromSetVisual (bool mode) {
    51     isVisual = mode;
    52     return true;
    53 }
    54 
    55 
    5649bool pmAstromVisualClose()
    5750{
     
    6861{
    6962    // make sure we want to plot this
    70     if (!plotRawStars || !isVisual) return true;
     63    if (!plotRawStars || !pmVisualIsVisual()) return true;
    7164
    7265    //set up plot region
    7366    if (!pmVisualInitWindow (&kapa, "psastro:plots")){
    74         isVisual = false;
    7567        return false;
    7668    }
     
    222214
    223215    // pause and wait for user input:
    224     pmVisualAskUser(&plotRawStars, &isVisual);
     216    pmVisualAskUser(&plotRawStars);
    225217
    226218    psFree (xVec);
     
    234226{
    235227    //make sure we want to plot this
    236     if (!isVisual || !plotRefStars) return true;
     228    if (!pmVisualIsVisual() || !plotRefStars) return true;
    237229
    238230    //set up plotting variables
    239231    if (!pmVisualInitWindow (&kapa, "psastro:plots")) {
    240         isVisual = false;
    241232        return false;
    242233    }
     
    284275
    285276    // pause and wait for user input:
    286     pmVisualAskUser(&plotRefStars, &isVisual);
     277    pmVisualAskUser(&plotRefStars);
    287278
    288279    psFree (xVec);
     
    301292
    302293    // make sure we want to plot this
    303     if ( !isVisual || !plotLumFunc ) return true;
     294    if ( !pmVisualIsVisual() || !plotLumFunc ) return true;
    304295
    305296    //set up plotting variables
    306297    if ( !pmVisualInitWindow (&kapa, "psastro:plots")){
    307         isVisual = false;
    308298        return false;
    309299    }
     
    377367
    378368        // pause and wait for user input:
    379         pmVisualAskUser (&plotLumFunc, &isVisual);
     369        pmVisualAskUser (&plotLumFunc);
    380370    }
    381371    return true;
     
    391381
    392382    //make sure we want to plot this
    393     if (!isVisual || !plotRemoveClumps) return true;
     383    if (!pmVisualIsVisual() || !plotRemoveClumps) return true;
    394384
    395385    //set up plot variables
    396386    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
    397         isVisual = false;
    398387        return false;
    399388    }
     
    480469
    481470    //ask for user input and finish
    482     pmVisualAskUser (&plotRemoveClumps, &isVisual);
     471    pmVisualAskUser (&plotRemoveClumps);
    483472    psFree (xVec);
    484473    psFree (yVec);
     
    496485
    497486    //make sure we want to plot this
    498     if (!isVisual || !plotOneChipFit)
     487    if (!pmVisualIsVisual() || !plotOneChipFit)
    499488        return true;
    500489
    501490    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    502         isVisual = false;
    503491        return false;
    504492    }
     
    511499
    512500    //ask for user input and finish
    513     pmVisualAskUser(&plotOneChipFit, &isVisual);
     501    pmVisualAskUser(&plotOneChipFit);
    514502    return true;
    515503}
     
    522510{
    523511    //make sure we want to plot this
    524     if(!isVisual || !plotFixChips) return true;
     512    if(!pmVisualIsVisual() || !plotFixChips) return true;
    525513
    526514    if(!pmVisualInitWindow(&kapa, "psastro:plots")) {
    527         isVisual = false;
    528515        return false;
    529516    }
     
    588575    KapaPlotVector (kapa, xNew->n, yNew->data.F32, "y");
    589576
    590     pmVisualAskUser(&plotFixChips, &isVisual);
     577    pmVisualAskUser(&plotFixChips);
    591578    psFree(xNew);
    592579    psFree(yNew);
     
    606593
    607594    //make sure we want to plot this
    608     if (!isVisual || !plotAstromGuessCheck) return true;
     595    if (!pmVisualIsVisual() || !plotAstromGuessCheck) return true;
    609596
    610597    //set up graph window
    611598    if ( !pmVisualInitWindow (&kapa, "psastro:plots")) {
    612         isVisual = false;
    613599        return false;
    614600    }
     
    686672    psFree(xResid);
    687673    psFree(yResid);
    688     pmVisualAskUser (&plotAstromGuessCheck, &isVisual);
     674    pmVisualAskUser (&plotAstromGuessCheck);
    689675    return true;
    690676}
     
    696682{
    697683    //make sure we want to plot this
    698     if (!isVisual || !plotCommonScale) return true;
     684    if (!pmVisualIsVisual() || !plotCommonScale) return true;
    699685
    700686    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
    701         isVisual = false;
    702687        return false;
    703688    }
     
    736721    KapaSendLabel (kapa, "Old Pixel Scale of FPA Chips (Not to Scale)", KAPA_LABEL_XP);
    737722
    738     pmVisualAskUser (&plotCommonScale, &isVisual);
     723    pmVisualAskUser (&plotCommonScale);
    739724
    740725    psFree(xVec);
     
    750735
    751736    //make sure we want to plot this
    752     if (!isVisual || !plotMosaicOneChip) return true;
     737    if (!pmVisualIsVisual() || !plotMosaicOneChip) return true;
    753738
    754739    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    755         isVisual = false;
    756740        return false;
    757741    }
     
    759743    //plot the residuals
    760744    if (!residPlot(rawstars, refstars, match, recipe, "Single Chip Fit Residuals - Mosaic Mode")) {
    761         isVisual = false;
     745        pmVisualSetVisual(false);
    762746        return false;
    763747    }
    764748
    765749    //ask for user input and finish
    766     pmVisualAskUser(&plotMosaicOneChip, &isVisual);
     750    pmVisualAskUser(&plotMosaicOneChip);
    767751
    768752    return true;
     
    775759{
    776760    //make sure we want to plot this
    777     if (!isVisual || !plotMosaicMatches) return true;
     761    if (!pmVisualIsVisual() || !plotMosaicMatches) return true;
    778762
    779763    char title[60];
     
    782766
    783767    if(!pmVisualInitWindow(&kapa, "psastro:plots") || !pmVisualInitWindow(&kapa2, "psastro:plots")) {
    784         isVisual = false;
    785768        return false;
    786769    }
    787770
    788771    if (!residPlot(rawstars, refstars, match, recipe, title)){
    789         isVisual = false;
     772        pmVisualSetVisual(false);
    790773        return false;
    791774    }
    792775
    793776    //ask for user input
    794     pmVisualAskUser (&plotMosaicMatches, &isVisual);
     777    pmVisualAskUser (&plotMosaicMatches);
    795778    return true;
    796779}
     
    807790{
    808791    //make sure we want to plot this
    809     if (!isVisual || !plotGridMatch) return true;
     792    if (!pmVisualIsVisual() || !plotGridMatch) return true;
    810793    if (!pmVisualInitWindow(&kapa, "psastro:plots")){
    811         isVisual = false;
    812794        return false;
    813795    }
     
    952934    KapaPlotVector (kapa, 2, yslice, "y");
    953935
    954     pmVisualAskUser(&plotGridMatch, &isVisual);
     936    pmVisualAskUser(&plotGridMatch);
    955937    psFree(dXplot);
    956938    psFree(dYplot);
     
    966948{
    967949    //make sure we want to plot this
    968     if (!isVisual || !plotTweak) return true;
     950    if (!pmVisualIsVisual() || !plotTweak) return true;
    969951    if (!pmVisualInitWindow(&kapa, "psastro:plots")) {
    970         isVisual = false;
    971952        return false;
    972953    }
     
    10511032                   KAPA_LABEL_XP);
    10521033
    1053     pmVisualAskUser(&plotTweak, &isVisual);
     1034    pmVisualAskUser(&plotTweak);
    10541035
    10551036    psFree(xIndices);
     
    13411322# else
    13421323
    1343 bool pmAstromSetVisual(bool mode) { return true; }
    13441324bool pmAstromVisualClose() { return true; }
    13451325bool pmAstromVisualPlotGridMatch (const psArray *raw, const psArray *ref, psImage *gridNP, double offsetX, double offsetY, double maxOffpix, double Scale, double Offset) { return true; }
  • branches/cnb_branch_20090215/psModules/src/astrom/pmAstrometryVisual.h

    r21422 r21536  
    2222    int sPeak;                          ///< sum of stars to peak bin
    2323} pmLumFunc;
    24 
    25 
    26 /** Enable or disable visual plotting for psastro routines
    27  * @param mode true/false to enable/disable plotting
    28  * @return true for success */
    29 bool pmAstromSetVisual(bool mode);
    3024
    3125
  • branches/cnb_branch_20090215/psModules/src/camera/pmFPACopy.c

    r21363 r21536  
    457457    psMetadataCopy(target->parent->concepts, source->parent->concepts);
    458458
     459    // Update the astrometric parameters
     460    target->toFPA = psMemIncrRefCounter (source->toFPA);
     461    target->fromFPA = psMemIncrRefCounter (source->fromFPA);
     462
     463    // Update the parent fpa astrometry parameters, or check that they match
     464    pmFPA *targetFPA = target->parent;
     465    pmFPA *sourceFPA = source->parent;
     466    // XXX should we require that both of these exist?
     467
     468    if (targetFPA && sourceFPA) {
     469        if (targetFPA->toSky) {
     470            psAssert (targetFPA->toSky == sourceFPA->toSky, "chips within FPA have inconsistent astrometry references");
     471        } else {
     472            targetFPA->toSky = psMemIncrRefCounter (sourceFPA->toSky);
     473        }
     474        if (targetFPA->toTPA) {
     475            psAssert (targetFPA->toTPA == sourceFPA->toTPA, "chips within FPA have inconsistent astrometry references");
     476        } else {
     477            targetFPA->toTPA = psMemIncrRefCounter (sourceFPA->toTPA);
     478        }
     479        if (targetFPA->fromTPA) {
     480            psAssert (targetFPA->fromTPA == sourceFPA->fromTPA, "chips within FPA have inconsistent astrometry references");
     481        } else {
     482            targetFPA->fromTPA = psMemIncrRefCounter (sourceFPA->fromTPA);
     483        }
     484    }
     485
    459486    target->data_exists = true;
    460487    return status;
  • branches/cnb_branch_20090215/psModules/src/detrend/pmShutterCorrection.h

    r21457 r21536  
    55 * @author Paul Price, IfA
    66 *
    7  * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2009-02-12 19:33:30 $
     7 * @version $Revision: 1.23.2.1 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2009-02-19 17:59:50 $
    99 * Copyright 2006 Institute for Astronomy, University of Hawaii
    1010 */
  • branches/cnb_branch_20090215/psModules/src/extras/pmVisual.c

    r21422 r21536  
    2828# define KAPAY 700
    2929
     30static bool isVisual = false;
     31
     32
     33bool pmVisualSetVisual(bool value) {
     34    isVisual = value;
     35    return true;
     36}
     37
     38
     39bool pmVisualIsVisual(void) {return isVisual;}
     40
     41bool pmVisualClose(void) {
     42    pmAstrometryVisualClose();
     43    pmSubtractionVisualClose();
     44    pmStackVisualClose();
     45    //XXX handle psphot
     46    //    psphotVisualClose();
     47    return true;
     48}
    3049
    3150bool pmVisualInitWindow (int *kapid, char *name) {
     
    3453        if (*kapid == -1) {
    3554            fprintf (stderr, "Failure to open kapa.\n");
     55            isVisual = false;
    3656            return false;
    3757        }
     
    5272
    5373
    54 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag)
     74bool pmVisualAskUser(bool *plotFlag)
    5575{
    5676    char key[10];
     
    6383    }
    6484    if (key[0] == 'a') {
    65         *packageFlag = false;
     85        isVisual = false;
    6686    }
    6787    return true;
     
    304324
    305325#else
    306 
     326bool pmVisualSetVisual(bool value) {return true;}
     327bool pmVisualIsVisual(void) {return false;}
     328bool pmVisualClose(void) {return true;}
    307329bool pmVisualInitWindow(int *kapid, char *name){return true;}
    308330bool pmVisualInitGraph (int kapa, void *section, void *graphdata){return true;}
    309331
    310 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag){return true;}
     332bool pmVisualAskUser(bool *plotFlag){return true;}
    311333bool pmVisualImStats(psImage *image, double *mean,
    312334                     double *stdev, double *min, double *max){return true;}
  • branches/cnb_branch_20090215/psModules/src/extras/pmVisual.h

    r21422 r21536  
    1010
    1111#if (HAVE_KAPA)
     12
     13
     14/** Globally enable or disable plotting
     15 * @param value - true to enable plotting
     16 * @return true
     17 */
     18bool pmVisualSetVisual(bool value);
     19
     20
     21/** Check whether plotting is enabled
     22 * @retrun true if plots should be generated
     23 */
     24bool pmVisualIsVisual(void);
     25
     26
     27/** Destroy plotting windows at the end of a run
     28 * @return true for success */
     29bool pmVisualClose(void);
    1230
    1331
     
    3250 * At the user's request, this will disable diagnostic plotting.
    3351 * @param plotFlag, set to false if this plot should be disabled in the future
    34  * @param packageFlag, set to false if all plots from this package (e.g. psastro, pmSubtraction)
    35  *                      should be disabled.
    3652 */
    37 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
     53bool pmVisualAskUser(bool *plotFlag);
    3854
    3955
     
    115131
    116132// kapa-specific data types are changed to void
     133bool pmVisualSetVisual(bool value);
     134bool pmVisualIsVisual(void);
     135bool pmVisualClose(void);
    117136bool pmVisualInitWindow (int *kapid, char *name);
    118137bool pmVisualInitGraph (int kapa, void *section, void *graphdata);
    119 bool pmVisualAskUser(bool *plotFlag, bool *packageFlag);
     138bool pmVisualAskUser(bool *plotFlag);
    120139bool pmVisualScaleImage(int kapaFD, psImage *inImage,
    121140                        const char *name, int channel, bool clip);
  • branches/cnb_branch_20090215/psModules/src/imcombine/Makefile.am

    r21422 r21536  
    1919        pmSubtractionThreads.c  \
    2020        pmPSFEnvelope.c         \
    21         pmSubtractionVisual.c
     21        pmSubtractionVisual.c   \
     22        pmStackVisual.c
    2223
    2324pkginclude_HEADERS = \
     
    3738        pmSubtractionThreads.h  \
    3839        pmPSFEnvelope.h         \
    39         pmSubtractionVisual.h
     40        pmSubtractionVisual.h   \
     41        pmStackVisual.h
    4042
    4143CLEANFILES = *~
  • branches/cnb_branch_20090215/psModules/src/imcombine/pmPSFEnvelope.c

    r21363 r21536  
    3030
    3131#include "pmPSFEnvelope.h"
    32 
    33 
    34 
    35 //#define TESTING                         // Enable test output
     32#include "pmStackVisual.h"
     33
     34
     35#define TESTING                         // Enable test output
    3636#define PEAK_FLUX 1.0e4                 // Peak flux for each source
    3737#define SKY_VALUE 0.0e0                 // Sky value for fake image
     
    162162            psStringAppend(&name, "psf_field_%03d.fits", i);
    163163            psFits *fits = psFitsOpen(name, "w");
     164            pmStackVisualPlotTestImage(fakeRO->image, name);
    164165            psFitsWriteImage(fits, NULL, fakeRO->image, 0, NULL);
    165166            psFitsClose(fits);
     
    179180        // Write out the envelope
    180181        psFits *fits = psFitsOpen("psf_field_envelope.fits", "w");
     182        pmStackVisualPlotTestImage(envelope, "psf_field_envelope.fits");
    181183        psFitsWriteImage(fits, NULL, envelope, 0, NULL);
    182184        psFitsClose(fits);
     
    231233        // Write out the envelope
    232234        psFits *fits = psFitsOpen("psf_field_full.fits", "w");
     235        pmStackVisualPlotTestImage(readout->image, "psf_field_full.fits");
    233236        psFitsWriteImage(fits, NULL, readout->image, 0, NULL);
    234237        psFitsClose(fits);
     
    312315        {
    313316            psFits *fits = psFitsOpen("psf_field_model.fits", "w");
     317            pmStackVisualPlotTestImage(generated->image, "psf_field_model.fits");
    314318            psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
    315319            psFitsClose(fits);
     
    318322        {
    319323            psFits *fits = psFitsOpen("psf_field_resid.fits", "w");
     324            pmStackVisualPlotTestImage(generated->image, "psf_field_resid.fits");
    320325            psFitsWriteImage(fits, NULL, generated->image, 0, NULL);
    321326            psFitsClose(fits);
  • branches/cnb_branch_20090215/psModules/src/imcombine/pmStack.c

    r21476 r21536  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2009-02-13 23:52:14 $
     10 *  @version $Revision: 1.48.2.1 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2009-02-19 17:59:50 $
    1212 *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
    1313 *
     
    3333#define NUM_DIRECT_STDEV 5              // For less than this number of values, measure stdev directly
    3434
    35 //#define TESTING                         // Enable test output
    36 //#define TEST_X 2318                     // x coordinate to examine
    37 //#define TEST_Y 2306                     // y coordinate to examine
     35//CNB change all of these to false
     36#define TESTING                         // Enable test output
     37#define TEST_X 2318                     // x coordinate to examine
     38#define TEST_Y 2306                     // y coordinate to examine
    3839
    3940
  • branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionIO.c

    r20355 r21536  
    1616
    1717#include "pmSubtractionIO.h"
     18#include "pmStackVisual.h"
    1819
    1920#define ARRAY_BUFFER 16                 // Number to add to array at a time
     
    144145    // CVS tags, used to identify the version of this file (in case incompatibilities are introduced)
    145146    psString cvsFile = psStringCopy("$RCSfile: pmSubtractionIO.c,v $");
    146     psString cvsRev  = psStringCopy("$Revision: 1.9 $");
    147     psString cvsDate = psStringCopy("$Date: 2008-10-24 21:21:06 $");
     147    psString cvsRev  = psStringCopy("$Revision: 1.9.18.1 $");
     148    psString cvsDate = psStringCopy("$Date: 2009-02-19 17:59:50 $");
    148149    psStringSubstitute(&cvsFile, NULL, "RCSfile: ");
    149150    psStringSubstitute(&cvsRev,  NULL, "Revision: ");
     
    167168
    168169    psImage *image = psMetadataLookupPtr(NULL, ro->analysis, PM_SUBTRACTION_ANALYSIS_KERNEL_IMAGE); // Image
     170    pmStackVisualPlotTestImage(image, "Subtraction_kernels.fits");
     171
    169172    if (image && !psFitsWriteImage(fits, header, image, 0, EXTNAME_IMAGE)) {
    170173        psError(PS_ERR_IO, false, "Unable to write subtraction kernel image.");
  • branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionVisual.c

    r21422 r21536  
    2828
    2929//variables to determine when things are plotted
    30 static bool isVisual             = false;
    3130static bool plotConvKernels      = true;
    3231static bool plotStamps           = true;
     
    4241// Initialization Routines
    4342
    44 /** start or stop plotting */
    45 bool pmSubtractionSetVisual (bool mode) {
    46     isVisual = mode;
    47     return true;
    48 }
    4943
    5044
     
    6559 *    @return true for success */
    6660bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {
    67     if (!isVisual || !plotConvKernels) return true;
     61    if (!pmVisualIsVisual() || !plotConvKernels) return true;
    6862    if (!pmVisualInitWindow(&kapa, "ppSub:Images")) {
    69         isVisual = false;
    7063        return false;
    7164    }
    7265    pmVisualScaleImage(kapa, convKernels, "Convolution_Kernels", 0, true);
    73     pmVisualAskUser(&plotConvKernels, &isVisual);
     66    pmVisualAskUser(&plotConvKernels);
    7467    return true;
    7568}
     
    8073    @return true for success */
    8174bool pmSubtractionVisualPlotStamps(pmSubtractionStampList *stamps, pmReadout *ro) {
    82     if (!isVisual || !plotStamps) return true;
     75    if (!pmVisualIsVisual() || !plotStamps) return true;
    8376    if (!pmVisualInitWindow (&kapa, "ppSub:Images")) {
    84         isVisual = false;
    8577        return false;
    8678    }
    8779    if (!pmVisualInitWindow (&kapa2, "ppSub:StampMasterImage")) {
    88         isVisual = false;
    8980        return false;
    9081    }
     
    145136    pmVisualScaleImage(kapa, canvas, "Subtraction_Stamps", 0, true);
    146137
    147     pmVisualAskUser(&plotStamps, &isVisual);
     138    pmVisualAskUser(&plotStamps);
    148139    return true;
    149140}
     
    152143bool pmSubtractionVisualPlotLeastSquares (pmSubtractionStampList *stamps, bool dual) {
    153144
    154     if (!isVisual || !plotLeastSquares) return true;
     145    if (!pmVisualIsVisual() || !plotLeastSquares) return true;
    155146    if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
    156         isVisual = false;
    157147        return false;
    158148    }
     
    209199    pmVisualScaleImage(kapa, canvas32, "Least_Squares", 0, true);
    210200
    211     pmVisualAskUser(&plotLeastSquares, &isVisual);
     201    pmVisualAskUser(&plotLeastSquares);
    212202    psFree(canvas);
    213203    psFree(canvas32);
     
    216206
    217207bool pmSubtractionVisualShowSubtraction(psImage *image, psImage *ref, psImage *sub) {
    218     if (!isVisual || !plotImage) return true;
     208    if (!pmVisualIsVisual() || !plotImage) return true;
    219209    if (!pmVisualInitWindow (&kapa, "PPSub:Images")) {
    220         isVisual = false;
    221210        return false;
    222211    }
     
    225214    pmVisualScaleImage(kapa, ref, "Reference", 1, true);
    226215    pmVisualScaleImage(kapa, sub, "Subtraction", 2, true);
    227     pmVisualAskUser(&plotImage, &isVisual);
     216    pmVisualAskUser(&plotImage);
    228217    return true;
    229218}
     
    267256
    268257#else
    269 bool pmSubtractionSetVisual (bool mode) {return true;}
    270258bool pmSubtractionVisualClose() {return true;}
    271259bool pmSubtractionVisualPlotConvKernels(psImage *convKernels) {return true;}
  • branches/cnb_branch_20090215/psModules/src/imcombine/pmSubtractionVisual.h

    r21422 r21536  
    22#define PM_SUBTRACTION_VISUAL_H
    33
    4 bool pmSubtractionSetVisual (bool mode);
    54bool pmSubtractionVisualClose();
    65bool pmSubtractionVisualPlotConvKernels(psImage *convKernels);
  • branches/cnb_branch_20090215/psModules/src/objects/Makefile.am

    r20946 r21536  
    3636        pmSourceIO_PS1_DEV_1.c \
    3737        pmSourceIO_PS1_CAL_0.c \
     38        pmSourceIO_CMF_PS1_V1.c \
    3839        pmSourcePlots.c \
    3940        pmSourcePlotPSFModel.c \
  • branches/cnb_branch_20090215/psModules/src/objects/pmModel.c

    r21381 r21536  
    66 *  @author EAM, IfA
    77 *
    8  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 20:54:14 $
     8 *  @version $Revision: 1.27.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5959    tmp->chisqNorm = 0.0;
    6060    tmp->nDOF  = 0;
     61    tmp->nPix  = 0;
    6162    tmp->nIter = 0;
    6263    tmp->radiusFit = 0;
     
    234235
    235236    if (model->residuals) {
    236         DX = xBin*(image->col0 - xCenter - dx) + model->residuals->xCenter + 0.5;
    237         DY = yBin*(image->row0 - yCenter - dy) + model->residuals->yCenter + 0.5;
    238         Ro = (model->residuals->Ro)   ? model->residuals->Ro->data.F32 : NULL;
    239         Rx = (model->residuals->Rx)   ? model->residuals->Rx->data.F32 : NULL;
    240         Ry = (model->residuals->Ry)   ? model->residuals->Ry->data.F32 : NULL;
    241         Rm = (model->residuals->mask) ? model->residuals->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
    242         if (Ro) {
    243             NX = model->residuals->Ro->numCols;
    244             NY = model->residuals->Ro->numRows;
    245         }           
     237        DX = xBin*(image->col0 - xCenter - dx) + model->residuals->xCenter + 0.5;
     238        DY = yBin*(image->row0 - yCenter - dy) + model->residuals->yCenter + 0.5;
     239        Ro = (model->residuals->Ro)   ? model->residuals->Ro->data.F32 : NULL;
     240        Rx = (model->residuals->Rx)   ? model->residuals->Rx->data.F32 : NULL;
     241        Ry = (model->residuals->Ry)   ? model->residuals->Ry->data.F32 : NULL;
     242        Rm = (model->residuals->mask) ? model->residuals->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
     243        if (Ro) {
     244            NX = model->residuals->Ro->numCols;
     245            NY = model->residuals->Ro->numRows;
     246        }
    246247    }
    247248
     
    255256
    256257            // XXX should we use using 0.5 pixel offset?
    257             // Convert to coordinate in parent image, with offset (dx,dy)
     258            // Convert to coordinate in parent image, with offset (dx,dy)
    258259            imageCol = ix + image->col0 - dx;
    259260            imageRow = iy + image->row0 - dy;
     
    275276                float rx = xBin*ix + DX;
    276277
    277                 int rx0 = rx - 0.5;
    278                 int rx1 = rx + 0.5;
    279                 int ry0 = ry - 0.5;
    280                 int ry1 = ry + 0.5;
    281 
    282                 if (rx0 < 0) goto skip;
    283                 if (ry0 < 0) goto skip;
    284                 if (rx1 >= NX) goto skip;
    285                 if (ry1 >= NY) goto skip;
    286 
    287                 // these go from 0.0 to 1.0 between the centers of the pixels
    288                 float fx = rx - 0.5 - rx0;
    289                 float Fx = 1.0 - fx;
    290                 float fy = ry - 0.5 - ry0;
    291                 float Fy = 1.0 - fy;
    292 
    293                 // check the residual image mask (if set). give up if any of the 4 pixels are masked.
    294                 if (Rm) {
    295                     if (Rm[ry0][rx0]) goto skip;
    296                     if (Rm[ry0][rx1]) goto skip;
    297                     if (Rm[ry1][rx0]) goto skip;
    298                     if (Rm[ry1][rx1]) goto skip;
    299                 }
    300 
    301                 // a possible further optimization if we re-use these values
    302                 // XXX allow for masked pixels, and add pixel weights
    303                 float V0 = (Ro[ry0][rx0]*Fx + Ro[ry0][rx1]*fx);
    304                 float V1 = (Ro[ry1][rx0]*Fx + Ro[ry1][rx1]*fx);
    305                 float Vo = V0*Fy + V1*fy;
    306                 if (!isfinite(Vo)) goto skip;
    307 
    308                 float Vx = 0.0;
    309                 float Vy = 0.0;
    310 
    311                 // skip Rx,Ry if Ro is masked
    312                 if (Rx && Ry && (mode & PM_MODEL_OP_RES1)) {
    313                     V0 = (Rx[ry0][rx0]*Fx + Rx[ry0][rx1]*fx);
    314                     V1 = (Rx[ry1][rx0]*Fx + Rx[ry1][rx1]*fx);
    315                     Vx = V0*Fy + V1*fy;
    316 
    317                     V0 = (Ry[ry0][rx0]*Fx + Ry[ry0][rx1]*fx);
    318                     V1 = (Ry[ry1][rx0]*Fx + Ry[ry1][rx1]*fx);
    319                     Vy = V0*Fy + V1*fy;
    320                 }
    321                 if (!isfinite(Vx)) goto skip;
    322                 if (!isfinite(Vy)) goto skip;
    323 
    324                 // 2D residual variations are set for the true source position
    325                 pixelValue += Io*(Vo + XoSave*Vx + XoSave*Vy);
     278                int rx0 = rx - 0.5;
     279                int rx1 = rx + 0.5;
     280                int ry0 = ry - 0.5;
     281                int ry1 = ry + 0.5;
     282
     283                if (rx0 < 0) goto skip;
     284                if (ry0 < 0) goto skip;
     285                if (rx1 >= NX) goto skip;
     286                if (ry1 >= NY) goto skip;
     287
     288                // these go from 0.0 to 1.0 between the centers of the pixels
     289                float fx = rx - 0.5 - rx0;
     290                float Fx = 1.0 - fx;
     291                float fy = ry - 0.5 - ry0;
     292                float Fy = 1.0 - fy;
     293
     294                // check the residual image mask (if set). give up if any of the 4 pixels are masked.
     295                if (Rm) {
     296                    if (Rm[ry0][rx0]) goto skip;
     297                    if (Rm[ry0][rx1]) goto skip;
     298                    if (Rm[ry1][rx0]) goto skip;
     299                    if (Rm[ry1][rx1]) goto skip;
     300                }
     301
     302                // a possible further optimization if we re-use these values
     303                // XXX allow for masked pixels, and add pixel weights
     304                float V0 = (Ro[ry0][rx0]*Fx + Ro[ry0][rx1]*fx);
     305                float V1 = (Ro[ry1][rx0]*Fx + Ro[ry1][rx1]*fx);
     306                float Vo = V0*Fy + V1*fy;
     307                if (!isfinite(Vo)) goto skip;
     308
     309                float Vx = 0.0;
     310                float Vy = 0.0;
     311
     312                // skip Rx,Ry if Ro is masked
     313                if (Rx && Ry && (mode & PM_MODEL_OP_RES1)) {
     314                    V0 = (Rx[ry0][rx0]*Fx + Rx[ry0][rx1]*fx);
     315                    V1 = (Rx[ry1][rx0]*Fx + Rx[ry1][rx1]*fx);
     316                    Vx = V0*Fy + V1*fy;
     317
     318                    V0 = (Ry[ry0][rx0]*Fx + Ry[ry0][rx1]*fx);
     319                    V1 = (Ry[ry1][rx0]*Fx + Ry[ry1][rx1]*fx);
     320                    Vy = V0*Fy + V1*fy;
     321                }
     322                if (!isfinite(Vx)) goto skip;
     323                if (!isfinite(Vy)) goto skip;
     324
     325                // 2D residual variations are set for the true source position
     326                pixelValue += Io*(Vo + XoSave*Vx + XoSave*Vy);
    326327            }
    327328
    328         skip:
     329        skip:
    329330            // add or subtract the value
    330331            if (add) {
  • branches/cnb_branch_20090215/psModules/src/objects/pmModel.h

    r21183 r21536  
    55 * @author EAM, IfA
    66 *
    7  * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    8  * @date $Date: 2009-01-27 06:39:38 $
     7 * @version $Revision: 1.18.8.1 $ $Name: not supported by cvs2svn $
     8 * @date $Date: 2009-02-19 17:59:50 $
    99 *
    1010 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9292    float mag;                          ///< integrated model magnitude
    9393    float magErr;                       ///< integrated model magnitude error
     94    int nPix;                           ///< number of pixels used for fit
    9495    int nDOF;                           ///< number of degrees of freedom
    9596    int nIter;                          ///< number of iterations to reach min
     
    150151    pmModel *model,                     ///< The input pmModel
    151152    pmModelOpMode mode,                 ///< mode to control how the model is added into the image
    152     psImageMaskType maskVal             ///< Value to mask
     153    psImageMaskType maskVal             ///< Value to mask
    153154);
    154155
     
    168169    pmModel *model,                     ///< The input pmModel
    169170    pmModelOpMode mode,                 ///< mode to control how the model is added into the image
    170     psImageMaskType maskVal             ///< Value to mask
     171    psImageMaskType maskVal             ///< Value to mask
    171172);
    172173
  • branches/cnb_branch_20090215/psModules/src/objects/pmPeaks.c

    r20937 r21536  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2008-12-08 02:51:14 $
     8 *  @version $Revision: 1.25.14.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828AddPeak(): A private function which allocates a psArray, if the peaks
    2929argument is NULL, otherwise it adds the peak to that array.
    30 XXX EAM : row,col now refer to image coords, NOT parent (since this is private) 
     30XXX EAM : row,col now refer to image coords, NOT parent (since this is private)
    3131XXX EAM : now also calculates fractional peak positions from 3x3 bicube region
    3232*****************************************************************************/
     
    6363        peak->xf = min.x + ix + image->col0;
    6464        peak->yf = min.y + iy + image->row0;
    65         peak->dx = NAN;
    66         peak->dy = NAN;
    67        
    68         // xf,yf must land on image with 0 pixel border
    69         peak->xf = PS_MAX (PS_MIN (peak->xf, image->numCols - 1), image->col0);
    70         peak->yf = PS_MAX (PS_MIN (peak->yf, image->numRows - 1), image->row0);
     65
     66        // These errors are fractional errors, and should be scaled by the
     67        // error on the peak pixel (see, eg, psphotFindPeaks)
     68        peak->dx = min.xErr;
     69        peak->dy = min.yErr;
     70
     71        // xf,yf must land on image with 0 pixel border
     72        peak->xf = PS_MAX (PS_MIN (peak->xf, image->numCols - 1), image->col0);
     73        peak->yf = PS_MAX (PS_MIN (peak->yf, image->numRows - 1), image->row0);
    7174    } else {
    7275        peak->xf = ix;
    7376        peak->yf = iy;
    74         peak->dx = NAN;
    75         peak->dy = NAN;
     77        peak->dx = NAN;
     78        peak->dy = NAN;
    7679    }
    7780
     
    8689getRowVectorFromImage(): a private function which simply returns a
    8790psVector containing the specified row of data from the psImage.
    88  
     91
    8992XXX: Is there a better way to do this?
    9093XXX EAM: does this really need to alloc a new vector???
     
    245248above the given threshold.  Returns a vector of type PS_TYPE_U32 containing
    246249the location (x value) of all peaks.
    247  
     250
    248251XXX: What types should be supported?  Only F32 is implemented.
    249  
     252
    250253XXX: We currently step through the input vector twice; once to determine the
    251254size of the output vector, then to set the values of the output vector.
     
    253256*****************************************************************************/
    254257psVector *pmPeaksInVector(const psVector *vector,
    255                         psF32 threshold)
     258                        psF32 threshold)
    256259{
    257260    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
     
    347350above the given threshold.  Returns a psArray containing location (x/y value)
    348351of all peaks.
    349  
     352
    350353XXX: I'm not convinced the peak type definition in the SDRS is mutually
    351354exclusive.  Some peaks can have multiple types.  Edges for sure.  Also, a
    352355digonal line with the same value at each point will have a peak for every
    353356point on that line.
    354  
     357
    355358XXX: This does not work if image has either a single row, or a single column.
    356  
     359
    357360The peak is returned in the image parent coordinates
    358361
  • branches/cnb_branch_20090215/psModules/src/objects/pmSource.c

    r21363 r21536  
    66 *  @author EAM, IfA: significant modifications.
    77 *
    8  *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 02:31:25 $
     8 *  @version $Revision: 1.69.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    113113    source->type = PM_SOURCE_TYPE_UNKNOWN;
    114114    source->mode = PM_SOURCE_MODE_DEFAULT;
     115    source->tmpFlags = 0;
    115116    source->extpars = NULL;
    116117    source->region = psRegionSet(NAN, NAN, NAN, NAN);
     
    534535    float INNER_RADIUS = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
    535536
     537    pmSourceMode noMoments = PM_SOURCE_MODE_MOMENTS_FAILURE | PM_SOURCE_MODE_SKYVAR_FAILURE | PM_SOURCE_MODE_SKY_FAILURE | PM_SOURCE_MODE_BELOW_MOMENTS_SN;
     538
    536539    // XXX allow clump size to be scaled relative to sigmas?
    537540    // make rough IDs based on clumpX,Y,DX,DY
     
    540543        pmSource *source = (pmSource *) sources->data[i];
    541544
    542         if (source->peak->x < region->x0) continue;
    543         if (source->peak->x > region->x1) continue;
    544         if (source->peak->y < region->y0) continue;
    545         if (source->peak->y > region->y1) continue;
    546 
    547         source->peak->type = 0;
     545        // psf clumps are found for image subregions:
     546        // skip sources not in this region
     547        if (source->peak->x <  region->x0) continue;
     548        if (source->peak->x >= region->x1) continue;
     549        if (source->peak->y <  region->y0) continue;
     550        if (source->peak->y >= region->y1) continue;
     551
     552        // should be set by pmSourceAlloc
     553        psAssert (source->type == PM_SOURCE_TYPE_UNKNOWN, "source type was not init-ed?");
    548554
    549555        // we are basically classifying by moments; use the default if not found
    550556        if (!source->moments) {
    551557            source->type = PM_SOURCE_TYPE_STAR;
     558            psAssert (source->mode & noMoments, "why is this source missing moments?");
    552559            Nstar++;
    553560            continue;
     
    10491056}
    10501057
     1058// sort by Seq (ascending)
     1059int pmSourceSortBySeq (const void **a, const void **b)
     1060{
     1061    pmSource *A = *(pmSource **)a;
     1062    pmSource *B = *(pmSource **)b;
     1063
     1064    int iA = A->seq;
     1065    int iB = B->seq;
     1066
     1067    int diff = iA - iB;
     1068    if (diff > 0) return (+1);
     1069    if (diff < 0) return (-1);
     1070    return (0);
     1071}
     1072
    10511073pmSourceMode pmSourceModeFromString (const char *name) {
    10521074  if (!strcasecmp (name, "DEFAULT"   )) return PM_SOURCE_MODE_DEFAULT;
     
    10661088  if (!strcasecmp (name, "CRLIMIT"   )) return PM_SOURCE_MODE_CR_LIMIT;
    10671089  if (!strcasecmp (name, "EXTLIMIT"  )) return PM_SOURCE_MODE_EXT_LIMIT;
    1068   if (!strcasecmp (name, "SUBTRACTED")) return PM_SOURCE_MODE_SUBTRACTED;
    10691090  return PM_SOURCE_MODE_DEFAULT;
    10701091}
     
    10881109    case PM_SOURCE_MODE_CR_LIMIT   : return psStringCopy ("CRLIMIT"   );
    10891110    case PM_SOURCE_MODE_EXT_LIMIT  : return psStringCopy ("EXTLIMIT"  );
    1090     case PM_SOURCE_MODE_SUBTRACTED : return psStringCopy ("SUBTRACTED");
    10911111    default:
    10921112      return NULL;
  • branches/cnb_branch_20090215/psModules/src/objects/pmSource.h

    r21363 r21536  
    33 * @author EAM, IfA; GLG, MHPCC
    44 *
    5  * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    6  * @date $Date: 2009-02-06 02:31:25 $
     5 * @version $Revision: 1.28.4.1 $ $Name: not supported by cvs2svn $
     6 * @date $Date: 2009-02-19 17:59:50 $
    77 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    88 */
     
    3535} pmSourceType;
    3636
     37// bit flags to distinguish analysis results
    3738typedef enum {
    38     PM_SOURCE_MODE_DEFAULT    = 0x0000, ///<
    39     PM_SOURCE_MODE_PSFMODEL   = 0x0001, ///< Source fitted with a psf model (linear or non-linear)
    40     PM_SOURCE_MODE_EXTMODEL   = 0x0002, ///< Source fitted with an extended-source model
    41     PM_SOURCE_MODE_FITTED     = 0x0004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
    42     PM_SOURCE_MODE_FAIL       = 0x0008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
    43     PM_SOURCE_MODE_POOR       = 0x0010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
    44     PM_SOURCE_MODE_PAIR       = 0x0020, ///< Source fitted with a double psf
    45     PM_SOURCE_MODE_PSFSTAR    = 0x0040, ///< Source used to define PSF model
    46     PM_SOURCE_MODE_SATSTAR    = 0x0080, ///< Source model peak is above saturation
    47     PM_SOURCE_MODE_BLEND      = 0x0100, ///< Source is a blend with other sourcers
    48     PM_SOURCE_MODE_EXTERNAL   = 0x0200, ///< Source based on supplied input position
    49     PM_SOURCE_MODE_BADPSF     = 0x0400, ///< Failed to get good estimate of object's PSF
    50     PM_SOURCE_MODE_DEFECT     = 0x0800, ///< Source is thought to be a defect
    51     PM_SOURCE_MODE_SATURATED  = 0x1000, ///< Source is thought to be saturated pixels (bleed trail)
    52     PM_SOURCE_MODE_CR_LIMIT   = 0x2000, ///< Source has crNsigma above limit
    53     PM_SOURCE_MODE_EXT_LIMIT  = 0x4000, ///< Source has extNsigma above limit
    54     PM_SOURCE_MODE_SUBTRACTED = 0x8000, ///< XXX this flag is actually only used internally (move)
     39    PM_SOURCE_MODE_DEFAULT          = 0x00000000, ///< Initial value: resets all bits
     40    PM_SOURCE_MODE_PSFMODEL         = 0x00000001, ///< Source fitted with a psf model (linear or non-linear)
     41    PM_SOURCE_MODE_EXTMODEL         = 0x00000002, ///< Source fitted with an extended-source model
     42    PM_SOURCE_MODE_FITTED           = 0x00000004, ///< Source fitted with non-linear model (PSF or EXT; good or bad)
     43    PM_SOURCE_MODE_FAIL             = 0x00000008, ///< Fit (non-linear) failed (non-converge, off-edge, run to zero)
     44    PM_SOURCE_MODE_POOR             = 0x00000010, ///< Fit succeeds, but low-SN, high-Chisq, or large (for PSF -- drop?)
     45    PM_SOURCE_MODE_PAIR             = 0x00000020, ///< Source fitted with a double psf
     46    PM_SOURCE_MODE_PSFSTAR          = 0x00000040, ///< Source used to define PSF model
     47    PM_SOURCE_MODE_SATSTAR          = 0x00000080, ///< Source model peak is above saturation
     48    PM_SOURCE_MODE_BLEND            = 0x00000100, ///< Source is a blend with other sourcers
     49    PM_SOURCE_MODE_EXTERNAL         = 0x00000200, ///< Source based on supplied input position
     50    PM_SOURCE_MODE_BADPSF           = 0x00000400, ///< Failed to get good estimate of object's PSF
     51    PM_SOURCE_MODE_DEFECT           = 0x00000800, ///< Source is thought to be a defect
     52    PM_SOURCE_MODE_SATURATED        = 0x00001000, ///< Source is thought to be saturated pixels (bleed trail)
     53    PM_SOURCE_MODE_CR_LIMIT         = 0x00002000, ///< Source has crNsigma above limit
     54    PM_SOURCE_MODE_EXT_LIMIT        = 0x00004000, ///< Source has extNsigma above limit
     55    PM_SOURCE_MODE_MOMENTS_FAILURE  = 0x00008000, ///< could not measure the moments
     56    PM_SOURCE_MODE_SKY_FAILURE      = 0x00010000, ///< could not measure the local sky
     57    PM_SOURCE_MODE_SKYVAR_FAILURE   = 0x00020000, ///< could not measure the local sky variance
     58    PM_SOURCE_MODE_BELOW_MOMENTS_SN = 0x00040000, ///< moments not measured due to low S/N
     59    PM_SOURCE_MODE_BIG_RADIUS       = 0x00100000, ///< poor moments for small radius, try large radius
     60    PM_SOURCE_MODE_AP_MAGS          = 0x00200000, ///< source has an aperture magnitude
     61    PM_SOURCE_MODE_BLEND_FIT        = 0x00400000, ///< source was fitted as a blend
     62    PM_SOURCE_MODE_EXTENDED_FIT     = 0x00800000, ///< full extended fit was used
     63    PM_SOURCE_MODE_EXTENDED_STATS   = 0x01000000, ///< extended aperture stats calculated
     64    PM_SOURCE_MODE_LINEAR_FIT       = 0x02000000, ///< source fitted with the linear fit
     65    PM_SOURCE_MODE_NONLINEAR_FIT    = 0x04000000, ///< source fitted with the non-linear fit
     66    PM_SOURCE_MODE_RADIAL_FLUX      = 0x08000000, ///< radial flux measurements calculated
     67    PM_SOURCE_MODE_SIZE_SKIPPED     = 0x10000000, ///< size could not be determined
    5568} pmSourceMode;
     69
     70typedef enum {
     71    PM_SOURCE_TMPF_MODEL_GUESS = 0x0001,
     72    PM_SOURCE_TMPF_SUBTRACTED  = 0x0002,
     73} pmSourceTmpF;
    5674
    5775/** pmSource data structure
     
    6886 */
    6987struct pmSource {
    70     const int id;                       ///< Unique ID for object
    71     int seq;                            ///< ID for output (generated on write)
     88    const int id;                       ///< Unique ID for object (generated on alloc)
     89    int seq;                            ///< ID for output (generated on write OR set on read)
    7290    pmPeak  *peak;                      ///< Description of peak pixel.
    7391    psImage *pixels;                    ///< Rectangular region including object pixels.
     
    83101    pmSourceType type;                  ///< Best identification of object.
    84102    pmSourceMode mode;                  ///< analysis flags set for object.
     103    pmSourceTmpF tmpFlags;              ///< internal-only flags
    85104    psArray *blends;                    ///< collection of sources thought to be confused with object
    86105    float psfMag;                       ///< calculated from flux in modelPSF
     
    240259bool pmSourceCachePSF (pmSource *source, psImageMaskType maskVal);
    241260
    242 int             pmSourceSortBySN (const void **a, const void **b);
    243 int             pmSourceSortByY (const void **a, const void **b);
     261int  pmSourceSortBySN (const void **a, const void **b);
     262int  pmSourceSortByY (const void **a, const void **b);
     263int  pmSourceSortBySeq (const void **a, const void **b);
    244264
    245265pmSourceMode pmSourceModeFromString (const char *name);
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceFitModel.c

    r21363 r21536  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 02:31:25 $
     8 *  @version $Revision: 1.30.4.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    184184    model->chisq = myMin->value;
    185185    model->nIter = myMin->iter;
     186    model->nPix  = y->n;
    186187    model->nDOF  = y->n - nParams;
    187188    model->flags |= PM_MODEL_STATUS_FITTED;
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.c

    r20937 r21536  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2008-12-08 02:51:14 $
     5 *  @version $Revision: 1.69.14.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2009-02-19 17:59:50 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    488488            }
    489489            if (!strcmp (exttype, "PS1_DEV_1")) {
    490                 status = pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname, xsrcname);
     490                status = pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname);
    491491            }
    492492            if (!strcmp (exttype, "PS1_CAL_0")) {
    493                 status = pmSourcesWrite_PS1_CAL_0 (file->fits, readout, sources, file->header, outhead, dataname, xsrcname);
     493                status = pmSourcesWrite_PS1_CAL_0 (file->fits, readout, sources, file->header, outhead, dataname);
     494            }
     495            if (!strcmp (exttype, "PS1_V1")) {
     496                status = pmSourcesWrite_CMF_PS1_V1 (file->fits, readout, sources, file->header, outhead, dataname);
    494497            }
    495498            if (xsrcname) {
     
    500503                  status = pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
    501504              }
     505              if (!strcmp (exttype, "PS1_V1")) {
     506                  status = pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, sources, xsrcname, recipe);
     507              }
    502508            }
    503509            if (xfitname) {
     
    507513              if (!strcmp (exttype, "PS1_CAL_0")) {
    508514                  status = pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname);
     515              }
     516              if (!strcmp (exttype, "PS1_V1")) {
     517                  status = pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, sources, xfitname);
    509518              }
    510519            }
     
    929938                sources = pmSourcesRead_PS1_DEV_1 (file->fits, hdu->header);
    930939            }
    931             if (!strcmp (exttype, "PS1_CAL_)")) {
    932                 sources = pmSourcesRead_PS1_CAL_0 (file->fits, hdu->header);
     940            if (!strcmp (exttype, "PS1_V1")) {
     941                sources = pmSourcesRead_CMF_PS1_V1 (file->fits, hdu->header);
    933942            }
    934943        }
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO.h

    r20741 r21536  
    44 * @author EAM, IfA; GLG, MHPCC
    55 *
    6  * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2008-11-14 02:11:45 $
     6 * @version $Revision: 1.19.16.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2009-02-19 17:59:50 $
    88 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    99 *
     
    2626bool pmSourcesWrite_SMPDATA (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
    2727bool pmSourcesWrite_PS1_DEV_0 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
    28 bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, char *xsrcname);
     28
     29bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
    2930bool pmSourcesWrite_PS1_DEV_1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
    3031bool pmSourcesWrite_PS1_DEV_1_XFIT (psFits *fits, psArray *sources, char *extname);
    3132
    32 bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, char *xsrcname);
     33bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
    3334bool pmSourcesWrite_PS1_CAL_0_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe);
    3435bool pmSourcesWrite_PS1_CAL_0_XFIT (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname);
     36
     37bool pmSourcesWrite_CMF_PS1_V1 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname);
     38bool pmSourcesWrite_CMF_PS1_V1_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe);
     39bool pmSourcesWrite_CMF_PS1_V1_XFIT (psFits *fits, psArray *sources, char *extname);
    3540
    3641bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config);
     
    4247psArray *pmSourcesRead_PS1_DEV_1 (psFits *fits, psMetadata *header);
    4348psArray *pmSourcesRead_PS1_CAL_0 (psFits *fits, psMetadata *header);
     49psArray *pmSourcesRead_CMF_PS1_V1 (psFits *fits, psMetadata *header);
    4450
    4551bool pmSourcesWritePSFs (psArray *sources, char *filename);
     
    6773bool pmReadoutCheckDataStatusForSources (const pmReadout *readout);
    6874
     75bool pmSourceLocalAstrometry (psSphere *ptSky, float *posAngle, float *pltScale, pmChip *chip, float xPos, float yPos);
     76
    6977/// @}
    7078# endif /* PM_SOURCE_IO_H */
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_CAL_0.c

    r20937 r21536  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2008-12-08 02:51:14 $
     5 *  @version $Revision: 1.2.14.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2009-02-19 17:59:50 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949// XXX how do I generate the source tables which I need to send to PSPS?
    5050
    51 bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader,
    52                                psMetadata *tableHeader, char *extname, char *xsrcname)
     51bool pmSourcesWrite_PS1_CAL_0 (psFits *fits, pmReadout *readout, psArray *sources,
     52                               psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
    5353{
    5454    PS_ASSERT_PTR_NON_NULL(fits, false);
     
    6868    pmFPA  *fpa  = chip->parent;
    6969    if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
    70         psWarning ("astrometry calibration is missing, no calibrated coords");
     70        psWarning ("astrometry calibration is missing, no calibrated coords");
    7171    }
    7272
     
    7777    float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
    7878    if (!status1 || !status2 || (exptime == 0.0)) {
    79         psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     79        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
    8080    } else {
    81         magOffset = zeropt + 2.5*log10(exptime);
     81        magOffset = zeropt + 2.5*log10(exptime);
    8282    }
    8383
     
    9090    for (i = 0; i < sources->n; i++) {
    9191        pmSource *source = (pmSource *) sources->data[i];
    92         if (source->seq == -1) {
    93             source->seq = i;
    94         }
     92        if (source->seq == -1) {
     93            source->seq = i;
     94        }
    9595
    9696        // no difference between PSF and non-PSF model
     
    104104            xErr = dPAR[PM_PAR_XPOS];
    105105            yErr = dPAR[PM_PAR_YPOS];
    106             if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
    107                 axes = pmPSF_ModelToAxes (PAR, 20.0);
    108             } else {
    109                 axes.major = NAN;
    110                 axes.minor = NAN;
    111                 axes.theta = NAN;
    112             }
    113             chisq = model->chisq;
    114 
    115             // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
    116             errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
     106            if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
     107                axes = pmPSF_ModelToAxes (PAR, 20.0);
     108            } else {
     109                axes.major = NAN;
     110                axes.minor = NAN;
     111                axes.theta = NAN;
     112            }
     113            chisq = model->chisq;
     114
     115            // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
     116            errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
    117117        } else {
    118118            xPos = source->peak->xf;
     
    123123            axes.minor = NAN;
    124124            axes.theta = NAN;
    125             chisq = NAN;
    126             errMag = NAN;
    127         }
    128 
    129         float calMag = source->psfMag + magOffset;
     125            chisq = NAN;
     126            errMag = NAN;
     127        }
     128
     129        float calMag = source->psfMag + magOffset;
    130130        float peakMag = (source->peak->flux > 0) ? -2.5*log10(source->peak->flux) : NAN;
    131131        psS16 nImageOverlap = 1;
    132132
    133         // generate RA,DEC
    134         psPlane ptCH, ptFP, ptTP;
    135         psSphere ptSky;
    136 
    137         ptCH.x = xPos;
    138         ptCH.y = yPos;
    139         if (chip->toFPA && fpa->toTPA && fpa->toSky) {
    140             psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
    141             psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    142             psDeproject (&ptSky, &ptTP, fpa->toSky);
    143         } else {
    144             ptSky.r = NAN;
    145             ptSky.d = NAN;
    146         }
     133        // generate RA,DEC
     134        psPlane ptCH, ptFP, ptTP;
     135        psSphere ptSky;
     136
     137        ptCH.x = xPos;
     138        ptCH.y = yPos;
     139        if (chip->toFPA && fpa->toTPA && fpa->toSky) {
     140            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     141            psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
     142            psDeproject (&ptSky, &ptTP, fpa->toSky);
     143        } else {
     144            ptSky.r = NAN;
     145            ptSky.d = NAN;
     146        }
    147147
    148148        row = psMetadataAlloc ();
     
    150150        psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF",           PS_DATA_F32, "PSF RA coordinate (degrees)",                ptSky.r*PS_DEG_RAD);
    151151        psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF",          PS_DATA_F32, "PSF DEC coordinate (degrees)",               ptSky.d*PS_DEG_RAD);
    152         // XXX need to do the error propagation correctly..
     152        // XXX need to do the error propagation correctly..
    153153        // psMetadataAdd (row, PS_LIST_TAIL, "RA_PSF_SIG",       PS_DATA_F32, "Sigma of PSF fit RA",                     dRA);
    154154        // psMetadataAdd (row, PS_LIST_TAIL, "DEC_PSF_SIG",      PS_DATA_F32, "Sigma of PSF fit DEC",                    dDEC);
     
    170170        psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32,  "Nsigma deviations from PSF to EXT",         source->extNsigma);
    171171
    172         // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
    173         // subtracted
    174 
    175         // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
    176         // edge; 3) any pixels in the 3x3 peak region are masked;
     172        // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
     173        // subtracted
     174
     175        // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
     176        // edge; 3) any pixels in the 3x3 peak region are masked;
    177177
    178178        // XXX these should be major and minor, not 'x' and 'y'
     
    277277        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    278278        source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    279         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;
     279        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;
    281281
    282282        pmPSF_AxesToModel (PAR, axes);
     
    289289        source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF");
    290290
    291         // note that some older versions used PSF_PROBABILITY: this was not well defined.
     291        // note that some older versions used PSF_PROBABILITY: this was not well defined.
    292292        model->chisq      = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
    293293        source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
     
    321321    pmFPA  *fpa  = chip->parent;
    322322    if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
    323         psWarning ("astrometry calibration is missing, no calibrated coords");
     323        psWarning ("astrometry calibration is missing, no calibrated coords");
    324324    }
    325325
     
    331331    float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
    332332    if (!status1 || !status2 || (exptime == 0.0)) {
    333         psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     333        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
    334334    } else {
    335         magOffset = zeropt + 2.5*log10(exptime);
    336         calMags = true;
     335        magOffset = zeropt + 2.5*log10(exptime);
     336        calMags = true;
    337337    }
    338338
     
    360360    // we write out all sources, regardless of quality.  the source flags tell us the state
    361361    for (int i = 0; i < sources->n; i++) {
    362         // skip source if it is not a ext sourc
    363         // XXX we have two places that extended source parameters are measured:
    364         // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
    365         // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
    366         // should we require both?
    367 
    368         pmSource *source = sources->data[i];
    369 
    370         // skip sources without measurements
    371         if (source->extpars == NULL) continue;
    372 
    373         // we require a PSF model fit (ignore the real crud)
    374         pmModel *model = source->modelPSF;
    375         if (model == NULL) continue;
    376 
    377         // XXX I need to split the extended models from the extended aperture measurements
    378         PAR = model->params->data.F32;
    379         dPAR = model->dparams->data.F32;
    380         xPos = PAR[PM_PAR_XPOS];
    381         yPos = PAR[PM_PAR_YPOS];
    382         xErr = dPAR[PM_PAR_XPOS];
    383         yErr = dPAR[PM_PAR_YPOS];
    384 
    385         // generate RA,DEC
    386         psPlane ptCH, ptFP, ptTP;
    387         psSphere ptSky;
    388 
    389         ptCH.x = xPos;
    390         ptCH.y = yPos;
    391         if (chip->toFPA && fpa->toTPA && fpa->toSky) {
    392             psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
    393             psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    394             psDeproject (&ptSky, &ptTP, fpa->toSky);
    395         } else {
    396             ptSky.r = NAN;
    397             ptSky.d = NAN;
    398         }
     362        // skip source if it is not a ext sourc
     363        // XXX we have two places that extended source parameters are measured:
     364        // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
     365        // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
     366        // should we require both?
     367
     368        pmSource *source = sources->data[i];
     369
     370        // skip sources without measurements
     371        if (source->extpars == NULL) continue;
     372
     373        // we require a PSF model fit (ignore the real crud)
     374        pmModel *model = source->modelPSF;
     375        if (model == NULL) continue;
     376
     377        // XXX I need to split the extended models from the extended aperture measurements
     378        PAR = model->params->data.F32;
     379        dPAR = model->dparams->data.F32;
     380        xPos = PAR[PM_PAR_XPOS];
     381        yPos = PAR[PM_PAR_YPOS];
     382        xErr = dPAR[PM_PAR_XPOS];
     383        yErr = dPAR[PM_PAR_YPOS];
     384
     385        // generate RA,DEC
     386        psPlane ptCH, ptFP, ptTP;
     387        psSphere ptSky;
     388
     389        ptCH.x = xPos;
     390        ptCH.y = yPos;
     391        if (chip->toFPA && fpa->toTPA && fpa->toSky) {
     392            psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     393            psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
     394            psDeproject (&ptSky, &ptTP, fpa->toSky);
     395        } else {
     396            ptSky.r = NAN;
     397            ptSky.d = NAN;
     398        }
    399399
    400400        row = psMetadataAlloc ();
     
    410410        psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in EXT y coordinate",                  yErr);
    411411
    412         // Petrosian measurements
    413         // XXX insert header data: petrosian ref radius, flux ratio
    414         if (doPetrosian) {
    415             pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
    416             if (petrosian) {
    417                 if (calMags) {
    418                     psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_CAL",    PS_DATA_F32, "Petrosian Magnitude (calibrated)", petrosian->mag + magOffset);
    419                 } else {
    420                     psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_INST",   PS_DATA_F32, "Petrosian Magnitude (instrumental)", petrosian->mag);
    421                 }
    422                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
    423                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
    424                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
    425             } else {
    426                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
    427                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
    428                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
    429                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
    430             }
    431         }
    432 
    433         // Kron measurements
    434         if (doKron) {
    435             pmSourceKronValues *kron = source->extpars->kron;
    436             if (kron) {
    437                 if (calMags) {
    438                     psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_CAL",  PS_DATA_F32, "Kron Magnitude",     kron->mag + magOffset);
    439                 } else {
    440                     psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_INST", PS_DATA_F32, "Kron Magnitude",     kron->mag);
    441                 }
    442                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
    443                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
    444                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
    445             } else {
    446                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
    447                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
    448                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
    449                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
    450             }
    451         }
    452 
    453         // Isophot measurements
    454         // XXX insert header data: isophotal level
    455         if (doIsophotal) {
    456             pmSourceIsophotalValues *isophot = source->extpars->isophot;
    457             if (isophot) {
    458                 if (calMags) {
    459                     psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_CAL",    PS_DATA_F32, "Isophot Magnitude (calibrated)",   isophot->mag + magOffset);
    460                 } else {
    461                     psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_INST",   PS_DATA_F32, "Isophot Magnitude (uncalibrated)", isophot->mag);
    462                 }
    463                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
    464                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
    465                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
    466             } else {
    467                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
    468                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
    469                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
    470                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
    471             }
    472         }
    473 
    474         // Flux Annuli
    475         if (doAnnuli) {
    476             pmSourceAnnuli *annuli = source->extpars->annuli;
    477             if (annuli) {
    478                 psVector *fluxVal = annuli->flux;
    479                 psVector *fluxErr = annuli->fluxErr;
    480                 psVector *fluxVar = annuli->fluxVar;
    481 
    482                 for (int j = 0; j < fluxVal->n; j++) {
    483                     char name[32];
    484                     sprintf (name, "FLUX_VAL_R_%02d", j);
    485                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
    486                     sprintf (name, "FLUX_ERR_R_%02d", j);
    487                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
    488                     sprintf (name, "FLUX_VAR_R_%02d", j);
    489                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
    490                 }
    491             } else {
    492                 for (int j = 0; j < radialBinsLower->n; j++) {
    493                     char name[32];
    494                     sprintf (name, "FLUX_VAL_R_%02d", j);
    495                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
    496                     sprintf (name, "FLUX_ERR_R_%02d", j);
    497                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
    498                     sprintf (name, "FLUX_VAR_R_%02d", j);
    499                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
    500                 }
    501             }
    502         }
    503 
    504         psArrayAdd (table, 100, row);
    505         psFree (row);
     412        // Petrosian measurements
     413        // XXX insert header data: petrosian ref radius, flux ratio
     414        if (doPetrosian) {
     415            pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
     416            if (petrosian) {
     417                if (calMags) {
     418                    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_CAL",    PS_DATA_F32, "Petrosian Magnitude (calibrated)", petrosian->mag + magOffset);
     419                } else {
     420                    psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_INST",   PS_DATA_F32, "Petrosian Magnitude (instrumental)", petrosian->mag);
     421                }
     422                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
     423                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
     424                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
     425            } else {
     426                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
     427                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
     428                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
     429                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
     430            }
     431        }
     432
     433        // Kron measurements
     434        if (doKron) {
     435            pmSourceKronValues *kron = source->extpars->kron;
     436            if (kron) {
     437                if (calMags) {
     438                    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_CAL",  PS_DATA_F32, "Kron Magnitude",     kron->mag + magOffset);
     439                } else {
     440                    psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_INST", PS_DATA_F32, "Kron Magnitude",     kron->mag);
     441                }
     442                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
     443                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
     444                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
     445            } else {
     446                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
     447                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
     448                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
     449                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
     450            }
     451        }
     452
     453        // Isophot measurements
     454        // XXX insert header data: isophotal level
     455        if (doIsophotal) {
     456            pmSourceIsophotalValues *isophot = source->extpars->isophot;
     457            if (isophot) {
     458                if (calMags) {
     459                    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_CAL",    PS_DATA_F32, "Isophot Magnitude (calibrated)",   isophot->mag + magOffset);
     460                } else {
     461                    psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_INST",   PS_DATA_F32, "Isophot Magnitude (uncalibrated)", isophot->mag);
     462                }
     463                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
     464                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
     465                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
     466            } else {
     467                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
     468                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
     469                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
     470                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
     471            }
     472        }
     473
     474        // Flux Annuli
     475        if (doAnnuli) {
     476            pmSourceAnnuli *annuli = source->extpars->annuli;
     477            if (annuli) {
     478                psVector *fluxVal = annuli->flux;
     479                psVector *fluxErr = annuli->fluxErr;
     480                psVector *fluxVar = annuli->fluxVar;
     481
     482                for (int j = 0; j < fluxVal->n; j++) {
     483                    char name[32];
     484                    sprintf (name, "FLUX_VAL_R_%02d", j);
     485                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
     486                    sprintf (name, "FLUX_ERR_R_%02d", j);
     487                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
     488                    sprintf (name, "FLUX_VAR_R_%02d", j);
     489                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
     490                }
     491            } else {
     492                for (int j = 0; j < radialBinsLower->n; j++) {
     493                    char name[32];
     494                    sprintf (name, "FLUX_VAL_R_%02d", j);
     495                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
     496                    sprintf (name, "FLUX_ERR_R_%02d", j);
     497                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
     498                    sprintf (name, "FLUX_VAR_R_%02d", j);
     499                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
     500                }
     501            }
     502        }
     503
     504        psArrayAdd (table, 100, row);
     505        psFree (row);
    506506    }
    507507
    508508    if (table->n == 0) {
    509         psFitsWriteBlank (fits, outhead, extname);
    510         psFree (outhead);
    511         psFree (table);
    512         return true;
     509        psFitsWriteBlank (fits, outhead, extname);
     510        psFree (outhead);
     511        psFree (table);
     512        return true;
    513513    }
    514514
    515515    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
    516516    if (!psFitsWriteTable (fits, outhead, table, extname)) {
    517         psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
    518         psFree (outhead);
    519         psFree(table);
    520         return false;
     517        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
     518        psFree (outhead);
     519        psFree(table);
     520        return false;
    521521    }
    522522    psFree (outhead);
     
    540540    pmFPA  *fpa  = chip->parent;
    541541    if (!chip->toFPA || !fpa->toTPA || !fpa->toSky) {
    542         psWarning ("astrometry calibration is missing, no calibrated coords");
     542        psWarning ("astrometry calibration is missing, no calibrated coords");
    543543    }
    544544
     
    549549    float zeropt  = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS");
    550550    if (!status1 || !status2 || (exptime == 0.0)) {
    551         psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
     551        psWarning ("exposure time or measured zero point not found for a readout, no calibrated mags");
    552552    } else {
    553         magOffset = zeropt + 2.5*log10(exptime);
     553        magOffset = zeropt + 2.5*log10(exptime);
    554554    }
    555555
     
    566566    int nParamMax = 0;
    567567    for (int i = 0; i < sources->n; i++) {
    568         pmSource *source = sources->data[i];
    569         if (source->modelFits == NULL) continue;
    570         for (int j = 0; j < source->modelFits->n; j++) {
    571             pmModel *model = source->modelFits->data[j];
    572             assert (model);
    573             nParamMax = PS_MAX (nParamMax, model->params->n);
    574         }
     568        pmSource *source = sources->data[i];
     569        if (source->modelFits == NULL) continue;
     570        for (int j = 0; j < source->modelFits->n; j++) {
     571            pmModel *model = source->modelFits->data[j];
     572            assert (model);
     573            nParamMax = PS_MAX (nParamMax, model->params->n);
     574        }
    575575    }
    576576
     
    580580    for (int i = 0; i < sources->n; i++) {
    581581
    582         pmSource *source = sources->data[i];
    583 
    584         // XXX if no model fits are saved, write out modelEXT?
    585         if (source->modelFits == NULL) continue;
    586 
    587         // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
    588         for (int j = 0; j < source->modelFits->n; j++) {
    589 
    590             // choose the convolved EXT model, if available, otherwise the simple one
    591             pmModel *model = source->modelFits->data[j];
    592             assert (model);
    593 
    594             PAR = model->params->data.F32;
    595             dPAR = model->dparams->data.F32;
    596             xPos = PAR[PM_PAR_XPOS];
    597             yPos = PAR[PM_PAR_YPOS];
    598             xErr = dPAR[PM_PAR_XPOS];
    599             yErr = dPAR[PM_PAR_YPOS];
    600 
    601             axes = pmPSF_ModelToAxes (PAR, 20.0);
    602 
    603             // generate RA,DEC
    604             psPlane ptCH, ptFP, ptTP;
    605             psSphere ptSky;
    606 
    607             ptCH.x = xPos;
    608             ptCH.y = yPos;
    609             if (chip->toFPA && fpa->toTPA && fpa->toSky) {
    610                 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
    611                 psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
    612                 psDeproject (&ptSky, &ptTP, fpa->toSky);
    613             } else {
    614                 ptSky.r = NAN;
    615                 ptSky.d = NAN;
    616             }
    617 
    618             row = psMetadataAlloc ();
    619 
    620             // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
    621             psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
    622             psMetadataAddF32 (row, PS_LIST_TAIL, "RA_EXT",           0, "EXT model RA (degrees)",                     ptSky.r);
    623             psMetadataAddF32 (row, PS_LIST_TAIL, "DEC_EXT",          0, "EXT model DEC (degrees)",                    ptSky.d);
    624             psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
    625             psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
    626             psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
    627             psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
    628             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_CAL_MAG",      0, "EXT fit calibrated magnitude",               model->mag + magOffset);
    629             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
    630             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
    631 
    632             psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
    633             psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
    634 
    635             // XXX these should be major and minor, not 'x' and 'y'
    636             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
    637             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
    638             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
    639 
    640             // write out the other generic parameters
    641             for (int k = 0; k < nParamMax; k++) {
    642                 if (k == PM_PAR_I0) continue;
    643                 if (k == PM_PAR_SKY) continue;
    644                 if (k == PM_PAR_XPOS) continue;
    645                 if (k == PM_PAR_YPOS) continue;
    646                 if (k == PM_PAR_SXX) continue;
    647                 if (k == PM_PAR_SXY) continue;
    648                 if (k == PM_PAR_SYY) continue;
    649 
    650                 snprintf (name, 64, "EXT_PAR_%02d", k);
    651 
    652                 if (k < model->params->n) {
    653                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
    654                 } else {
    655                     psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
    656                 }
    657             }
    658 
    659             // XXX other parameters which may be set.
    660             // XXX flag / value to define the model
    661             // XXX write out the model type, fit status flags
    662 
    663             psArrayAdd (table, 100, row);
    664             psFree (row);
    665         }
     582        pmSource *source = sources->data[i];
     583
     584        // XXX if no model fits are saved, write out modelEXT?
     585        if (source->modelFits == NULL) continue;
     586
     587        // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
     588        for (int j = 0; j < source->modelFits->n; j++) {
     589
     590            // choose the convolved EXT model, if available, otherwise the simple one
     591            pmModel *model = source->modelFits->data[j];
     592            assert (model);
     593
     594            PAR = model->params->data.F32;
     595            dPAR = model->dparams->data.F32;
     596            xPos = PAR[PM_PAR_XPOS];
     597            yPos = PAR[PM_PAR_YPOS];
     598            xErr = dPAR[PM_PAR_XPOS];
     599            yErr = dPAR[PM_PAR_YPOS];
     600
     601            axes = pmPSF_ModelToAxes (PAR, 20.0);
     602
     603            // generate RA,DEC
     604            psPlane ptCH, ptFP, ptTP;
     605            psSphere ptSky;
     606
     607            ptCH.x = xPos;
     608            ptCH.y = yPos;
     609            if (chip->toFPA && fpa->toTPA && fpa->toSky) {
     610                psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);
     611                psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);
     612                psDeproject (&ptSky, &ptTP, fpa->toSky);
     613            } else {
     614                ptSky.r = NAN;
     615                ptSky.d = NAN;
     616            }
     617
     618            row = psMetadataAlloc ();
     619
     620            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
     621            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
     622            psMetadataAddF32 (row, PS_LIST_TAIL, "RA_EXT",           0, "EXT model RA (degrees)",                     ptSky.r);
     623            psMetadataAddF32 (row, PS_LIST_TAIL, "DEC_EXT",          0, "EXT model DEC (degrees)",                    ptSky.d);
     624            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
     625            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
     626            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
     627            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
     628            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_CAL_MAG",      0, "EXT fit calibrated magnitude",               model->mag + magOffset);
     629            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
     630            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
     631
     632            psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
     633            psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
     634
     635            // XXX these should be major and minor, not 'x' and 'y'
     636            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
     637            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
     638            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
     639
     640            // write out the other generic parameters
     641            for (int k = 0; k < nParamMax; k++) {
     642                if (k == PM_PAR_I0) continue;
     643                if (k == PM_PAR_SKY) continue;
     644                if (k == PM_PAR_XPOS) continue;
     645                if (k == PM_PAR_YPOS) continue;
     646                if (k == PM_PAR_SXX) continue;
     647                if (k == PM_PAR_SXY) continue;
     648                if (k == PM_PAR_SYY) continue;
     649
     650                snprintf (name, 64, "EXT_PAR_%02d", k);
     651
     652                if (k < model->params->n) {
     653                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
     654                } else {
     655                    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
     656                }
     657            }
     658
     659            // XXX other parameters which may be set.
     660            // XXX flag / value to define the model
     661            // XXX write out the model type, fit status flags
     662
     663            psArrayAdd (table, 100, row);
     664            psFree (row);
     665        }
    666666    }
    667667
    668668    if (table->n == 0) {
    669         psFitsWriteBlank (fits, outhead, extname);
    670         psFree (outhead);
    671         psFree (table);
    672         return true;
     669        psFitsWriteBlank (fits, outhead, extname);
     670        psFree (outhead);
     671        psFree (table);
     672        return true;
    673673    }
    674674
    675675    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
    676676    if (!psFitsWriteTable (fits, outhead, table, extname)) {
    677         psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
    678         psFree (outhead);
    679         psFree(table);
    680         return false;
     677        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
     678        psFree (outhead);
     679        psFree(table);
     680        return false;
    681681    }
    682682    psFree (outhead);
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceIO_PS1_DEV_1.c

    r20937 r21536  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2008-12-08 02:51:14 $
     5 *  @version $Revision: 1.14.14.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2009-02-19 17:59:50 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4949// XXX how do I generate the source tables which I need to send to PSPS?
    5050
    51 bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources, psMetadata *imageHeader,
    52                                psMetadata *tableHeader, char *extname, char *xsrcname)
     51bool pmSourcesWrite_PS1_DEV_1 (psFits *fits, psArray *sources,
     52                               psMetadata *imageHeader, psMetadata *tableHeader, char *extname)
    5353{
    5454    PS_ASSERT_PTR_NON_NULL(fits, false);
     
    7373    for (i = 0; i < sources->n; i++) {
    7474        pmSource *source = (pmSource *) sources->data[i];
    75         if (source->seq == -1) {
    76             source->seq = i;
    77         }
     75        if (source->seq == -1) {
     76            source->seq = i;
     77        }
    7878
    7979        // no difference between PSF and non-PSF model
     
    8787            xErr = dPAR[PM_PAR_XPOS];
    8888            yErr = dPAR[PM_PAR_YPOS];
    89             if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
    90                 axes = pmPSF_ModelToAxes (PAR, 20.0);
    91             } else {
    92                 axes.major = NAN;
    93                 axes.minor = NAN;
    94                 axes.theta = NAN;
    95             }
    96             chisq = model->chisq;
    97 
    98             // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
    99             errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
     89            if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) {
     90                axes = pmPSF_ModelToAxes (PAR, 20.0);
     91            } else {
     92                axes.major = NAN;
     93                axes.minor = NAN;
     94                axes.theta = NAN;
     95            }
     96            chisq = model->chisq;
     97
     98            // need to determine the PSF photometry error: source->errMag is the error on the 'best' model mag.
     99            errMag = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0];
    100100        } else {
    101101            xPos = source->peak->xf;
     
    106106            axes.minor = NAN;
    107107            axes.theta = NAN;
    108             chisq = NAN;
    109             errMag = NAN;
     108            chisq = NAN;
     109            errMag = NAN;
    110110        }
    111111
     
    130130        psMetadataAdd (row, PS_LIST_TAIL, "EXT_NSIGMA",       PS_DATA_F32,  "Nsigma deviations from PSF to EXT",         source->extNsigma);
    131131
    132         // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
    133         // subtracted
    134 
    135         // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
    136         // edge; 3) any pixels in the 3x3 peak region are masked;
    137 
    138         // CR_NSIGMA and
     132        // EXT_NSIGMA will be NAN if: 1) contour ellipse is imaginary; 2) source is not
     133        // subtracted
     134
     135        // CR_NSIGMA will be NAN if: 1) source is not subtracted; 2) source is on the image
     136        // edge; 3) any pixels in the 3x3 peak region are masked;
     137
     138        // CR_NSIGMA and
    139139
    140140        // XXX these should be major and minor, not 'x' and 'y'
     
    247247        source->psfMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG");
    248248        source->errMag    = psMetadataLookupF32 (&status, row, "PSF_INST_MAG_SIG");
    249         PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
    250         dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
     249        PAR[PM_PAR_I0]    = (isfinite(source->psfMag)) ? pow(10.0, -0.4*source->psfMag) : NAN;
     250        dPAR[PM_PAR_I0]   = (isfinite(source->psfMag)) ? PAR[PM_PAR_I0] * source->errMag : NAN;
    251251
    252252        pmPSF_AxesToModel (PAR, axes);
     
    259259        source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF");
    260260
    261         // note that some older versions used PSF_PROBABILITY: this was not well defined.
     261        // note that some older versions used PSF_PROBABILITY: this was not well defined.
    262262        model->chisq      = psMetadataLookupF32 (&status, row, "PSF_CHISQ");
    263263        source->crNsigma  = psMetadataLookupF32 (&status, row, "CR_NSIGMA");
     
    311311    // we write out all sources, regardless of quality.  the source flags tell us the state
    312312    for (int i = 0; i < sources->n; i++) {
    313         // skip source if it is not a ext sourc
    314         // XXX we have two places that extended source parameters are measured:
    315         // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
    316         // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
    317         // should we require both?
    318 
    319         pmSource *source = sources->data[i];
    320 
    321         // skip sources without measurements
    322         if (source->extpars == NULL) continue;
    323 
    324         // we require a PSF model fit (ignore the real crud)
    325         pmModel *model = source->modelPSF;
    326         if (model == NULL) continue;
    327 
    328         // XXX I need to split the extended models from the extended aperture measurements
    329         PAR = model->params->data.F32;
    330         dPAR = model->dparams->data.F32;
    331         xPos = PAR[PM_PAR_XPOS];
    332         yPos = PAR[PM_PAR_YPOS];
    333         xErr = dPAR[PM_PAR_XPOS];
    334         yErr = dPAR[PM_PAR_YPOS];
     313        // skip source if it is not a ext sourc
     314        // XXX we have two places that extended source parameters are measured:
     315        // psphotExtendedSources, which measures the aperture-like parameters and (potentially) the psf-convolved extended source models,
     316        // psphotFitEXT, which does the simple extended source model fit (not psf-convolved)
     317        // should we require both?
     318
     319        pmSource *source = sources->data[i];
     320
     321        // skip sources without measurements
     322        if (source->extpars == NULL) continue;
     323
     324        // we require a PSF model fit (ignore the real crud)
     325        pmModel *model = source->modelPSF;
     326        if (model == NULL) continue;
     327
     328        // XXX I need to split the extended models from the extended aperture measurements
     329        PAR = model->params->data.F32;
     330        dPAR = model->dparams->data.F32;
     331        xPos = PAR[PM_PAR_XPOS];
     332        yPos = PAR[PM_PAR_YPOS];
     333        xErr = dPAR[PM_PAR_XPOS];
     334        yErr = dPAR[PM_PAR_YPOS];
    335335
    336336        row = psMetadataAlloc ();
     
    343343        psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG",        PS_DATA_F32, "Sigma in EXT y coordinate",                  yErr);
    344344
    345         // Petrosian measurements
    346         // XXX insert header data: petrosian ref radius, flux ratio
    347         if (doPetrosian) {
    348             pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
    349             if (petrosian) {
    350                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
    351                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
    352                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
    353                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
    354             } else {
    355                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
    356                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
    357                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
    358                 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
    359             }
    360         }
    361 
    362         // Kron measurements
    363         if (doKron) {
    364             pmSourceKronValues *kron = source->extpars->kron;
    365             if (kron) {
    366                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
    367                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
    368                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
    369                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
    370             } else {
    371                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
    372                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
    373                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
    374                 psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
    375             }
    376         }
    377 
    378         // Isophot measurements
    379         // XXX insert header data: isophotal level
    380         if (doIsophotal) {
    381             pmSourceIsophotalValues *isophot = source->extpars->isophot;
    382             if (isophot) {
    383                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
    384                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
    385                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
    386                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
    387             } else {
    388                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
    389                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
    390                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
    391                 psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
    392             }
    393         }
    394 
    395         // Flux Annuli
    396         if (doAnnuli) {
    397             pmSourceAnnuli *annuli = source->extpars->annuli;
    398             if (annuli) {
    399                 psVector *fluxVal = annuli->flux;
    400                 psVector *fluxErr = annuli->fluxErr;
    401                 psVector *fluxVar = annuli->fluxVar;
    402 
    403                 for (int j = 0; j < fluxVal->n; j++) {
    404                     char name[32];
    405                     sprintf (name, "FLUX_VAL_R_%02d", j);
    406                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
    407                     sprintf (name, "FLUX_ERR_R_%02d", j);
    408                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
    409                     sprintf (name, "FLUX_VAR_R_%02d", j);
    410                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
    411                 }
    412             } else {
    413                 for (int j = 0; j < radialBinsLower->n; j++) {
    414                     char name[32];
    415                     sprintf (name, "FLUX_VAL_R_%02d", j);
    416                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
    417                     sprintf (name, "FLUX_ERR_R_%02d", j);
    418                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
    419                     sprintf (name, "FLUX_VAR_R_%02d", j);
    420                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
    421                 }
    422             }
    423         }
    424 
    425         psArrayAdd (table, 100, row);
    426         psFree (row);
     345        // Petrosian measurements
     346        // XXX insert header data: petrosian ref radius, flux ratio
     347        if (doPetrosian) {
     348            pmSourcePetrosianValues *petrosian = source->extpars->petrosian;
     349            if (petrosian) {
     350                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       petrosian->mag);
     351                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr);
     352                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          petrosian->rad);
     353                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    petrosian->radErr);
     354            } else {
     355                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG",        PS_DATA_F32, "Petrosian Magnitude",       NAN);
     356                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR",    PS_DATA_F32, "Petrosian Magnitude Error", NAN);
     357                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS",     PS_DATA_F32, "Petrosian Radius",          NAN);
     358                psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error",    NAN);
     359            }
     360        }
     361
     362        // Kron measurements
     363        if (doKron) {
     364            pmSourceKronValues *kron = source->extpars->kron;
     365            if (kron) {
     366                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       kron->mag);
     367                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", kron->magErr);
     368                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          kron->rad);
     369                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    kron->radErr);
     370            } else {
     371                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG",        PS_DATA_F32, "Kron Magnitude",       NAN);
     372                psMetadataAdd (row, PS_LIST_TAIL, "KRON_MAG_ERR",    PS_DATA_F32, "Kron Magnitude Error", NAN);
     373                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS",     PS_DATA_F32, "Kron Radius",          NAN);
     374                psMetadataAdd (row, PS_LIST_TAIL, "KRON_RADIUS_ERR", PS_DATA_F32, "Kron Radius Error",    NAN);
     375            }
     376        }
     377
     378        // Isophot measurements
     379        // XXX insert header data: isophotal level
     380        if (doIsophotal) {
     381            pmSourceIsophotalValues *isophot = source->extpars->isophot;
     382            if (isophot) {
     383                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       isophot->mag);
     384                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", isophot->magErr);
     385                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          isophot->rad);
     386                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    isophot->radErr);
     387            } else {
     388                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG",        PS_DATA_F32, "Isophot Magnitude",       NAN);
     389                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_MAG_ERR",    PS_DATA_F32, "Isophot Magnitude Error", NAN);
     390                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS",     PS_DATA_F32, "Isophot Radius",          NAN);
     391                psMetadataAdd (row, PS_LIST_TAIL, "ISOPHOT_RADIUS_ERR", PS_DATA_F32, "Isophot Radius Error",    NAN);
     392            }
     393        }
     394
     395        // Flux Annuli
     396        if (doAnnuli) {
     397            pmSourceAnnuli *annuli = source->extpars->annuli;
     398            if (annuli) {
     399                psVector *fluxVal = annuli->flux;
     400                psVector *fluxErr = annuli->fluxErr;
     401                psVector *fluxVar = annuli->fluxVar;
     402
     403                for (int j = 0; j < fluxVal->n; j++) {
     404                    char name[32];
     405                    sprintf (name, "FLUX_VAL_R_%02d", j);
     406                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]);
     407                    sprintf (name, "FLUX_ERR_R_%02d", j);
     408                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]);
     409                    sprintf (name, "FLUX_VAR_R_%02d", j);
     410                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]);
     411                }
     412            } else {
     413                for (int j = 0; j < radialBinsLower->n; j++) {
     414                    char name[32];
     415                    sprintf (name, "FLUX_VAL_R_%02d", j);
     416                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN);
     417                    sprintf (name, "FLUX_ERR_R_%02d", j);
     418                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN);
     419                    sprintf (name, "FLUX_VAR_R_%02d", j);
     420                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN);
     421                }
     422            }
     423        }
     424
     425        psArrayAdd (table, 100, row);
     426        psFree (row);
    427427    }
    428428
    429429    if (table->n == 0) {
    430         psFitsWriteBlank (fits, outhead, extname);
    431         psFree (outhead);
    432         psFree (table);
    433         return true;
     430        psFitsWriteBlank (fits, outhead, extname);
     431        psFree (outhead);
     432        psFree (table);
     433        return true;
    434434    }
    435435
    436436    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
    437437    if (!psFitsWriteTable (fits, outhead, table, extname)) {
    438         psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
    439         psFree (outhead);
    440         psFree(table);
    441         return false;
     438        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
     439        psFree (outhead);
     440        psFree(table);
     441        return false;
    442442    }
    443443    psFree (outhead);
     
    470470    int nParamMax = 0;
    471471    for (int i = 0; i < sources->n; i++) {
    472         pmSource *source = sources->data[i];
    473         if (source->modelFits == NULL) continue;
    474         for (int j = 0; j < source->modelFits->n; j++) {
    475             pmModel *model = source->modelFits->data[j];
    476             assert (model);
    477             nParamMax = PS_MAX (nParamMax, model->params->n);
    478         }
     472        pmSource *source = sources->data[i];
     473        if (source->modelFits == NULL) continue;
     474        for (int j = 0; j < source->modelFits->n; j++) {
     475            pmModel *model = source->modelFits->data[j];
     476            assert (model);
     477            nParamMax = PS_MAX (nParamMax, model->params->n);
     478        }
    479479    }
    480480
     
    484484    for (int i = 0; i < sources->n; i++) {
    485485
    486         pmSource *source = sources->data[i];
    487 
    488         // XXX if no model fits are saved, write out modelEXT?
    489         if (source->modelFits == NULL) continue;
    490 
    491         // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
    492         for (int j = 0; j < source->modelFits->n; j++) {
    493 
    494             // choose the convolved EXT model, if available, otherwise the simple one
    495             pmModel *model = source->modelFits->data[j];
    496             assert (model);
    497 
    498             PAR = model->params->data.F32;
    499             dPAR = model->dparams->data.F32;
    500             xPos = PAR[PM_PAR_XPOS];
    501             yPos = PAR[PM_PAR_YPOS];
    502             xErr = dPAR[PM_PAR_XPOS];
    503             yErr = dPAR[PM_PAR_YPOS];
    504 
    505             axes = pmPSF_ModelToAxes (PAR, 20.0);
    506 
    507             row = psMetadataAlloc ();
    508 
    509             // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
    510             psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
    511             psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
    512             psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
    513             psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
    514             psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
    515             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
    516             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
    517 
    518             psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
    519             psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
    520 
    521             // XXX these should be major and minor, not 'x' and 'y'
    522             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
    523             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
    524             psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
    525 
    526             // write out the other generic parameters
    527             for (int k = 0; k < nParamMax; k++) {
    528                 if (k == PM_PAR_I0) continue;
    529                 if (k == PM_PAR_SKY) continue;
    530                 if (k == PM_PAR_XPOS) continue;
    531                 if (k == PM_PAR_YPOS) continue;
    532                 if (k == PM_PAR_SXX) continue;
    533                 if (k == PM_PAR_SXY) continue;
    534                 if (k == PM_PAR_SYY) continue;
    535 
    536                 snprintf (name, 64, "EXT_PAR_%02d", k);
    537 
    538                 if (k < model->params->n) {
    539                     psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
    540                 } else {
    541                     psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
    542                 }
    543             }
    544 
    545             // XXX other parameters which may be set.
    546             // XXX flag / value to define the model
    547             // XXX write out the model type, fit status flags
    548 
    549             psArrayAdd (table, 100, row);
    550             psFree (row);
    551         }
     486        pmSource *source = sources->data[i];
     487
     488        // XXX if no model fits are saved, write out modelEXT?
     489        if (source->modelFits == NULL) continue;
     490
     491        // We have multiple sources : need to flag the one used to subtract the light (the 'best' model)
     492        for (int j = 0; j < source->modelFits->n; j++) {
     493
     494            // choose the convolved EXT model, if available, otherwise the simple one
     495            pmModel *model = source->modelFits->data[j];
     496            assert (model);
     497
     498            PAR = model->params->data.F32;
     499            dPAR = model->dparams->data.F32;
     500            xPos = PAR[PM_PAR_XPOS];
     501            yPos = PAR[PM_PAR_YPOS];
     502            xErr = dPAR[PM_PAR_XPOS];
     503            yErr = dPAR[PM_PAR_YPOS];
     504
     505            axes = pmPSF_ModelToAxes (PAR, 20.0);
     506
     507            row = psMetadataAlloc ();
     508
     509            // XXX we are not writing out the mode (flags) or the type (psf, ext, etc)
     510            psMetadataAddU32 (row, PS_LIST_TAIL, "IPP_IDET",         0, "IPP detection identifier index",             source->seq);
     511            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT",            0, "EXT model x coordinate",                     xPos);
     512            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT",            0, "EXT model y coordinate",                     yPos);
     513            psMetadataAddF32 (row, PS_LIST_TAIL, "X_EXT_SIG",        0, "Sigma in EXT x coordinate",                  xErr);
     514            psMetadataAddF32 (row, PS_LIST_TAIL, "Y_EXT_SIG",        0, "Sigma in EXT y coordinate",                  yErr);
     515            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG",     0, "EXT fit instrumental magnitude",             model->mag);
     516            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_INST_MAG_SIG", 0, "Sigma of PSF instrumental magnitude",        model->magErr);
     517
     518            psMetadataAddF32 (row, PS_LIST_TAIL, "NPARAMS",          0, "number of model parameters",                 model->params->n);
     519            psMetadataAddStr (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "name of model",                              pmModelClassGetName (model->type));
     520
     521            // XXX these should be major and minor, not 'x' and 'y'
     522            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MAJ",    0, "EXT width in x coordinate",                  axes.major);
     523            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_WIDTH_MIN",    0, "EXT width in y coordinate",                  axes.minor);
     524            psMetadataAddF32 (row, PS_LIST_TAIL, "EXT_THETA",        0, "EXT orientation angle",                      axes.theta);
     525
     526            // write out the other generic parameters
     527            for (int k = 0; k < nParamMax; k++) {
     528                if (k == PM_PAR_I0) continue;
     529                if (k == PM_PAR_SKY) continue;
     530                if (k == PM_PAR_XPOS) continue;
     531                if (k == PM_PAR_YPOS) continue;
     532                if (k == PM_PAR_SXX) continue;
     533                if (k == PM_PAR_SXY) continue;
     534                if (k == PM_PAR_SYY) continue;
     535
     536                snprintf (name, 64, "EXT_PAR_%02d", k);
     537
     538                if (k < model->params->n) {
     539                    psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "", model->params->data.F32[k]);
     540                } else {
     541                    psMetadataAddF32 (row, PS_LIST_TAIL, name, PS_DATA_F32, "", NAN);
     542                }
     543            }
     544
     545            // XXX other parameters which may be set.
     546            // XXX flag / value to define the model
     547            // XXX write out the model type, fit status flags
     548
     549            psArrayAdd (table, 100, row);
     550            psFree (row);
     551        }
    552552    }
    553553
    554554    if (table->n == 0) {
    555         psFitsWriteBlank (fits, outhead, extname);
    556         psFree (outhead);
    557         psFree (table);
    558         return true;
     555        psFitsWriteBlank (fits, outhead, extname);
     556        psFree (outhead);
     557        psFree (table);
     558        return true;
    559559    }
    560560
    561561    psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname);
    562562    if (!psFitsWriteTable (fits, outhead, table, extname)) {
    563         psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
    564         psFree (outhead);
    565         psFree(table);
    566         return false;
     563        psError(PS_ERR_IO, false, "writing ext data %s\n", extname);
     564        psFree (outhead);
     565        psFree(table);
     566        return false;
    567567    }
    568568    psFree (outhead);
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.c

    r21363 r21536  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2009-02-06 02:31:25 $
     5 *  @version $Revision: 1.49.4.1 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2009-02-19 17:59:50 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    145145    // measure the contribution of included pixels
    146146    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    147         pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal);
     147        pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
    148148    }
    149149
     
    164164    // XXX full model or just analytical?
    165165    // XXX use pmSourceAdd instead?
    166     if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     166    if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    167167        pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
    168168    }
     
    170170    // if we are measuring aperture photometry and applying the growth correction,
    171171    // we need to shift the flux in the selected pixels (but not the mask)
    172     // psImageShift ();
    173172    psImage *flux = NULL, *mask = NULL; // Star flux and mask images, to photometer
    174173    if (mode & PM_SOURCE_PHOT_INTERP) {
     
    186185        }
    187186
    188         // XXX this is test code to verify the shift is doing the right thing (seems to be)
    189         # if (0)
    190             // measure centroid of unshifted gaussian (should be 16.0,16.0)
    191         {
    192             psImage *image = source->pixels;
    193             float xo = 0.0;
    194             float yo = 0.0;
    195             float xo2 = 0.0;
    196             float yo2 = 0.0;
    197             float no = 0.0;
    198             for (int j = 0; j < image->numRows; j++)
    199             {
    200                 for (int i = 0; i < image->numCols; i++) {
    201                     xo += i*image->data.F32[j][i];
    202                     yo += j*image->data.F32[j][i];
    203                     xo2 += i*i*image->data.F32[j][i];
    204                     yo2 += j*j*image->data.F32[j][i];
    205                     no += image->data.F32[j][i];
    206                 }
    207             }
    208             xo /= no;
    209             yo /= no;
    210             xo2 = sqrt (xo2/no - xo*xo);
    211             yo2 = sqrt (yo2/no - yo*yo);
    212             fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
    213         }
    214 
    215         // measure centroid of unshifted gaussian (should be 16.0,16.0)
    216         {
    217             psImage *image = flux;
    218             float xo = 0.0;
    219             float yo = 0.0;
    220             float xo2 = 0.0;
    221             float yo2 = 0.0;
    222             float no = 0.0;
    223             for (int j = 0; j < image->numRows; j++)
    224             {
    225                 for (int i = 0; i < image->numCols; i++) {
    226                     xo += i*image->data.F32[j][i];
    227                     yo += j*image->data.F32[j][i];
    228                     xo2 += i*i*image->data.F32[j][i];
    229                     yo2 += j*j*image->data.F32[j][i];
    230                     no += image->data.F32[j][i];
    231                 }
    232             }
    233             xo /= no;
    234             yo /= no;
    235             xo2 = sqrt (xo2/no - xo*xo);
    236             yo2 = sqrt (yo2/no - yo*yo);
    237             fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
    238         }
    239         # endif
    240 
    241187    } else {
    242188        flux = source->pixels;
     
    269215    // if source was originally subtracted, re-subtract object, leave local sky
    270216    // XXX replace with pmSourceSub...
    271     if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     217    if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    272218        pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
    273219    }
     
    344290
    345291// return source aperture magnitude
    346 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal)
     292bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal)
    347293{
    348294    PS_ASSERT_PTR_NON_NULL(pixWeight, false);
    349     PS_ASSERT_PTR_NON_NULL(image, false);
    350295    PS_ASSERT_PTR_NON_NULL(mask, false);
    351296    PS_ASSERT_PTR_NON_NULL(model, false);
     
    377322    Yo = params->data.F32[PM_PAR_YPOS];
    378323
    379     dX = Xo - image->col0;
    380     dP = image->numCols - dX;
     324    dX = Xo - mask->col0;
     325    dP = mask->numCols - dX;
    381326    DX = PS_MAX(dX, dP);
    382     NX = image->numCols;
    383 
    384     dY = Yo - image->row0;
    385     dP = image->numRows - dY;
     327    NX = mask->numCols;
     328
     329    dY = Yo - mask->row0;
     330    dP = mask->numRows - dY;
    386331    DY = PS_MAX(dY, dP);
    387     NY = image->numRows;
     332    NY = mask->numRows;
    388333
    389334    // measure modelSum and validSum.  this function is applied to a sources' subimage.  the
     
    612557# endif
    613558
     559// determine chisq, etc for linear normalization-only fit
    614560bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *variance,
    615561                    psImageMaskType maskVal)
     
    632578        }
    633579    }
     580    model->nPix = Npix;
    634581    model->nDOF = Npix - 1;
    635582    model->chisq = dC;
     
    817764}
    818765
     766// XXX this is test code to verify the shift is doing the right thing (seems to be)
     767# if (0)
     768// measure centroid of unshifted gaussian (should be 16.0,16.0)
     769        {
     770          psImage *image = source->pixels;
     771          float xo = 0.0;
     772          float yo = 0.0;
     773          float xo2 = 0.0;
     774          float yo2 = 0.0;
     775          float no = 0.0;
     776          for (int j = 0; j < image->numRows; j++)
     777          {
     778            for (int i = 0; i < image->numCols; i++) {
     779              xo += i*image->data.F32[j][i];
     780              yo += j*image->data.F32[j][i];
     781              xo2 += i*i*image->data.F32[j][i];
     782              yo2 += j*j*image->data.F32[j][i];
     783              no += image->data.F32[j][i];
     784            }
     785          }
     786          xo /= no;
     787          yo /= no;
     788          xo2 = sqrt (xo2/no - xo*xo);
     789          yo2 = sqrt (yo2/no - yo*yo);
     790          fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
     791        }
     792
     793// measure centroid of unshifted gaussian (should be 16.0,16.0)
     794        {
     795          psImage *image = flux;
     796          float xo = 0.0;
     797          float yo = 0.0;
     798          float xo2 = 0.0;
     799          float yo2 = 0.0;
     800          float no = 0.0;
     801          for (int j = 0; j < image->numRows; j++)
     802          {
     803            for (int i = 0; i < image->numCols; i++) {
     804              xo += i*image->data.F32[j][i];
     805              yo += j*image->data.F32[j][i];
     806              xo2 += i*i*image->data.F32[j][i];
     807              yo2 += j*j*image->data.F32[j][i];
     808              no += image->data.F32[j][i];
     809            }
     810          }
     811          xo /= no;
     812          yo /= no;
     813          xo2 = sqrt (xo2/no - xo*xo);
     814          yo2 = sqrt (yo2/no - yo*yo);
     815          fprintf (stderr, "pre-shift centroid: %f,%f, sigma: %f,%f: flux: %f\n", xo, yo, xo2, yo2, no);
     816        }
     817# endif
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourcePhotometry.h

    r21183 r21536  
    44 * @author EAM, IfA; GLG, MHPCC
    55 *
    6  * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2009-01-27 06:39:38 $
     6 * @version $Revision: 1.12.8.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2009-02-19 17:59:50 $
    88 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    99 */
     
    4646    psImage *image,                     ///< image pixels to be used
    4747    psImage *mask,                      ///< mask of pixels to ignore
    48     psImageMaskType maskVal             ///< Value to mask
     48    psImageMaskType maskVal             ///< Value to mask
    4949);
    5050
    5151bool pmSourceMagnitudesInit (psMetadata *config);
    5252bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal);
    53 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psImageMaskType maskVal);
     53bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal);
    5454bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal);
    5555
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceVisual.c

    r21183 r21536  
    99# if (HAVE_KAPA)
    1010# include <kapa.h>
     11#include "pmVisual.h"
    1112
    1213// functions used to visualize the analysis as it goes
    1314// these are invoked by the -visual options
    1415
    15 static bool isVisual = false;
    1616static int kapa1 = -1;
    1717// static int kapa2 = -1;
     
    2020bool pmSourcePlotPoints3D (int myKapa, Graphdata *graphdata, psVector *xn, psVector *yn, psVector *zn, float theta, float phi);
    2121
    22 bool pmSourceSetVisual (bool mode) {
    23 
    24     isVisual = mode;
    25     return true;
    26 }
    2722
    2823bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask) {
    2924
    30     KapaSection section;  // put the positive profile in one and the residuals in another? 
     25    KapaSection section;  // put the positive profile in one and the residuals in another?
    3126
    3227    Graphdata graphdata;
    3328
    34     if (!isVisual) return true;
     29    if (!pmVisualIsVisual()) return true;
    3530
    3631    if (kapa1 == -1) {
    3732        kapa1 = KapaOpenNamedSocket ("kapa", "pmSource:plots");
    38         if (kapa1 == -1) {
    39             fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    40             isVisual = false;
    41             return false;
    42         }
    43     } 
     33        if (kapa1 == -1) {
     34            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
     35            pmVisualSetVisual(false);
     36            return false;
     37        }
     38    }
    4439
    4540    KapaClearPlots (kapa1);
     
    5550
    5651    for (int i = 0; i < x->n; i++) {
    57         model->data.F32[i] = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
    58         resid->data.F32[i] = param->data.F32[i] - model->data.F32[i];
    59         if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
    60         min = PS_MIN (min, resid->data.F32[i]);
    61         max = PS_MAX (max, resid->data.F32[i]);
    62         Min = PS_MIN (min, param->data.F32[i]);
    63         Max = PS_MAX (max, param->data.F32[i]);
     52        model->data.F32[i] = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
     53        resid->data.F32[i] = param->data.F32[i] - model->data.F32[i];
     54        if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
     55        min = PS_MIN (min, resid->data.F32[i]);
     56        max = PS_MAX (max, resid->data.F32[i]);
     57        Min = PS_MIN (min, param->data.F32[i]);
     58        Max = PS_MAX (max, param->data.F32[i]);
    6459    }
    6560
     
    7065    psVector *Fn = psVectorAlloc (x->n, PS_TYPE_F32);
    7166    for (int i = 0; i < x->n; i++) {
    72         xn->data.F32[i] = x->data.F32[i] / 5000.0;
    73         yn->data.F32[i] = y->data.F32[i] / 5000.0;
    74         zn->data.F32[i] = (resid->data.F32[i] - min) / (max - min);
    75         Zn->data.F32[i] = (param->data.F32[i] - Min) / (Max - Min);
    76         Fn->data.F32[i] = (model->data.F32[i] - Min) / (Max - Min);
     67        xn->data.F32[i] = x->data.F32[i] / 5000.0;
     68        yn->data.F32[i] = y->data.F32[i] / 5000.0;
     69        zn->data.F32[i] = (resid->data.F32[i] - min) / (max - min);
     70        Zn->data.F32[i] = (param->data.F32[i] - Min) / (Max - Min);
     71        Fn->data.F32[i] = (model->data.F32[i] - Min) / (Max - Min);
    7772    }
    7873
     
    155150    fprintf (stdout, "[c]ontinue? ");
    156151    if (!fgets(key, 8, stdin)) {
    157         psWarning("Unable to read option");
     152        psWarning("Unable to read option");
    158153    }
    159154    return true;
     
    173168
    174169    for (int i = 0; i < xn->n; i++) {
    175         xv->data.F32[2*i+0] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi) + zn->data.F32[i]*sin(theta)*sin(phi);
    176         yv->data.F32[2*i+0] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi) + zn->data.F32[i]*cos(theta)*sin(phi);
    177         zv->data.F32[2*i+0] = -yn->data.F32[i]*sin(phi)   + zn->data.F32[i]*cos(phi);
    178         xv->data.F32[2*i+1] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi);
    179         yv->data.F32[2*i+1] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi);
    180         zv->data.F32[2*i+1] = -yn->data.F32[i]*sin(phi);
    181         graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+0]);
    182         graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+0]);
    183         graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+0]);
    184         graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+0]);
    185         graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+1]);
    186         graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+1]);
    187         graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+1]);
    188         graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+1]);
     170        xv->data.F32[2*i+0] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi) + zn->data.F32[i]*sin(theta)*sin(phi);
     171        yv->data.F32[2*i+0] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi) + zn->data.F32[i]*cos(theta)*sin(phi);
     172        zv->data.F32[2*i+0] = -yn->data.F32[i]*sin(phi)   + zn->data.F32[i]*cos(phi);
     173        xv->data.F32[2*i+1] = +xn->data.F32[i]*cos(theta) + yn->data.F32[i]*sin(theta)*cos(phi);
     174        yv->data.F32[2*i+1] = -xn->data.F32[i]*sin(theta) + yn->data.F32[i]*cos(theta)*cos(phi);
     175        zv->data.F32[2*i+1] = -yn->data.F32[i]*sin(phi);
     176        graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+0]);
     177        graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+0]);
     178        graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+0]);
     179        graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+0]);
     180        graphdata->xmin = PS_MIN(graphdata->xmin, xv->data.F32[2*i+1]);
     181        graphdata->xmax = PS_MAX(graphdata->xmax, xv->data.F32[2*i+1]);
     182        graphdata->ymin = PS_MIN(graphdata->ymin, zv->data.F32[2*i+1]);
     183        graphdata->ymax = PS_MAX(graphdata->ymax, zv->data.F32[2*i+1]);
    189184    }
    190185    xv->n = xn->n;
  • branches/cnb_branch_20090215/psModules/src/objects/pmSourceVisual.h

    r20582 r21536  
    11/* @file  pmKapaPlots.h
    2  * @brief functions to make plots with the external program 'kapa' 
     2 * @brief functions to make plots with the external program 'kapa'
    33 *
    44 * @author EAM, IfA
    55 *
    6  * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2008-11-08 01:52:34 $
     6 * @version $Revision: 1.1.16.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2009-02-19 17:59:50 $
    88 * Copyright 2006 Institute for Astronomy, University of Hawaii
    99 */
     
    1515/// @{
    1616
    17 bool pmSourceSetVisual (bool mode);
    1817bool pmSourceVisualPSFModelResid (pmTrend2D *trend, psVector *x, psVector *y, psVector *param, psVector *mask);
    1918
  • branches/cnb_branch_20090215/psastro/src/psastroArguments.c

    r21422 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:25:34 $
     8 *  @version $Revision: 1.34.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    100100    if ((N = psArgumentGet (argc, argv, "-visual"))) {
    101101        psArgumentRemove (N, &argc, argv);
    102         pmAstromSetVisual (true);
     102        pmVisualSetVisual (true);
    103103    }
    104104
  • branches/cnb_branch_20090215/psastro/src/psastroCleanup.c

    r21422 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-09 21:25:34 $
     8 *  @version $Revision: 1.8.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    1616
    1717    psFree (config);
    18     pmAstromVisualClose ();
     18    pmVisualClose ();
    1919
    2020    psTimerStop ();
  • branches/cnb_branch_20090215/psconfig/tagsets/ipp-2.7.perl

    r21405 r21536  
    33  00    Module::Build                  Module-Build-0.2806.tar.gz               0.2806         
    44  01    ExtUtils::MakeMaker            ExtUtils-MakeMaker-6.31.tar.gz           0         
    5   02    Params::Validate               Params-Validate-0.87-eam.tar.gz          0.77         
     5  02    Params::Validate               Params-Validate-0.87-eam-v1.tar.gz       0.77         
    66#  02    Apache::Test                   Apache-Test-1.29.tar.gz                  1.29
    77  03    DateTime::TimeZone             DateTime-TimeZone-0.59.tar.gz            0         
  • branches/cnb_branch_20090215/psphot/src/psphot.h

    r21392 r21536  
    167167
    168168// psphotVisual functions
    169 bool psphotSetVisual (bool mode);
    170169bool psphotVisualShowImage (pmReadout *readout);
    171170bool psphotVisualShowBackground (pmConfig *config, const pmFPAview *view, pmReadout *readout);
  • branches/cnb_branch_20090215/psphot/src/psphotAddNoise.c

    r21183 r21536  
    5050
    5151        // skip sources which were not subtracted
    52         if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) continue;
     52        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
    5353
    5454        // select appropriate model
  • branches/cnb_branch_20090215/psphot/src/psphotApResid.c

    r21359 r21536  
    11# include "psphotInternal.h"
    2 
    3 bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal);
    42
    53# define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; }
     
    9593        for (int j = 0; j < cells->n; j++) {
    9694
    97             if (nThreads) {
    98                 // allocate a job -- if threads are not defined, this just runs the job
    99                 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
    100 
    101                 psArrayAdd(job->args, 1, cells->data[j]); // sources
    102                 psArrayAdd(job->args, 1, psf);
    103                 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
    104                 PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    105 
    106                 PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
    107                 PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
    108 
    109                 if (!psThreadJobAddPending(job)) {
    110                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    111                     psFree (job);
    112                     return false;
    113                 }
    114                 psFree(job);
    115             } else {
     95            // allocate a job -- if threads are not defined, this just runs the job
     96            psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
     97
     98            psArrayAdd(job->args, 1, cells->data[j]); // sources
     99            psArrayAdd(job->args, 1, psf);
     100            PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
     101            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     102
     103            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
     104            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
     105
     106            if (!psThreadJobAddPending(job)) {
     107                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     108                psFree (job);
     109                return false;
     110            }
     111            psFree(job);
     112
     113# if (0)
    116114                int nskip = 0;
    117115                int nfail = 0;
     
    123121                Nskip += nskip;
    124122                Nfail += nfail;
    125             }           
     123# endif
    126124
    127125        }
    128126
    129         if (nThreads) {
    130             // wait for the threads to finish and manage results
    131             if (!psThreadPoolWait (false)) {
    132                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    133                 return false;
     127        // wait for the threads to finish and manage results
     128        if (!psThreadPoolWait (false)) {
     129            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     130            return false;
     131        }
     132
     133        // we have only supplied one type of job, so we can assume the types here
     134        psThreadJob *job = NULL;
     135        while ((job = psThreadJobGetDone()) != NULL) {
     136            if (job->args->n < 1) {
     137                fprintf (stderr, "error with job\n");
     138            } else {
     139                psScalar *scalar = NULL;
     140                scalar = job->args->data[4];
     141                Nskip += scalar->data.S32;
     142                scalar = job->args->data[5];
     143                Nfail += scalar->data.S32;
    134144            }
    135 
    136             // we have only supplied one type of job, so we can assume the types here
    137             psThreadJob *job = NULL;
    138             while ((job = psThreadJobGetDone()) != NULL) {
    139                 if (job->args->n < 1) {
    140                     fprintf (stderr, "error with job\n");
    141                 } else {
    142                     psScalar *scalar = NULL;
    143                     scalar = job->args->data[4];
    144                     Nskip += scalar->data.S32;
    145                     scalar = job->args->data[5];
    146                     Nfail += scalar->data.S32;
    147                 }
    148                 psFree(job);
    149             }
     145            psFree(job);
    150146        }
    151147    }
     
    497493            continue;
    498494        }
     495        source->mode |= PM_SOURCE_MODE_AP_MAGS;
    499496    }
    500497
     
    509506}
    510507
     508# if (0)
    511509bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal) {
    512510
     
    542540    return true;
    543541}
     542# endif
  • branches/cnb_branch_20090215/psphot/src/psphotArguments.c

    r21458 r21536  
    8282    if ((N = psArgumentGet (argc, argv, "-visual"))) {
    8383        psArgumentRemove (N, &argc, argv);
    84         psphotSetVisual (true);
    85         // pmSourceSetVisual (true);
     84        pmVisualSetVisual(true);
    8685    }
    8786
  • branches/cnb_branch_20090215/psphot/src/psphotBlendFit.c

    r21366 r21536  
    11# include "psphotInternal.h"
    2 
    3 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources);
    42
    53// XXX I don't like this name
     
    6260        for (int j = 0; j < cells->n; j++) {
    6361
    64             if (nThreads) {
    65                 // allocate a job -- if threads are not defined, this just runs the job
    66                 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT");
    67                 psArray *newSources = psArrayAllocEmpty(16);
    68 
    69                 psArrayAdd(job->args, 1, readout);
    70                 psArrayAdd(job->args, 1, recipe);
    71                 psArrayAdd(job->args, 1, cells->data[j]); // sources
    72                 psArrayAdd(job->args, 1, psf);
    73                 psArrayAdd(job->args, 1, newSources); // return for new sources
    74                 psFree (newSources);
    75 
    76                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
    77                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
    78                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
    79                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
    80 
    81                 if (!psThreadJobAddPending(job)) {
    82                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    83                     psFree (job);
    84                     return NULL;
    85                 }
    86                 psFree(job);
    87             } else {
     62            // allocate a job -- if threads are not defined, this just runs the job
     63            psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT");
     64            psArray *newSources = psArrayAllocEmpty(16);
     65
     66            psArrayAdd(job->args, 1, readout);
     67            psArrayAdd(job->args, 1, recipe);
     68            psArrayAdd(job->args, 1, cells->data[j]); // sources
     69            psArrayAdd(job->args, 1, psf);
     70            psArrayAdd(job->args, 1, newSources); // return for new sources
     71            psFree (newSources);
     72
     73            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit
     74            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf
     75            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next
     76            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
     77
     78            if (!psThreadJobAddPending(job)) {
     79                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     80                psFree (job);
     81                return NULL;
     82            }
     83            psFree(job);
     84
     85# if (0)
     86            {
    8887                int nfit = 0;
    8988                int npsf = 0;
     
    107106                psFree (newSources);
    108107            }
    109         }
    110 
    111         if (nThreads) {
    112             // wait for the threads to finish and manage results
    113             if (!psThreadPoolWait (false)) {
    114                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    115                 return NULL;
    116             }
    117 
    118             // we have only supplied one type of job, so we can assume the types here
    119             psThreadJob *job = NULL;
    120             while ((job = psThreadJobGetDone()) != NULL) {
    121                 if (job->args->n < 1) {
    122                     fprintf (stderr, "error with job\n");
    123                 } else {
    124                     psScalar *scalar = NULL;
    125                     scalar = job->args->data[5];
    126                     Nfit += scalar->data.S32;
    127                     scalar = job->args->data[6];
    128                     Npsf += scalar->data.S32;
    129                     scalar = job->args->data[7];
    130                     Next += scalar->data.S32;
    131                     scalar = job->args->data[8];
    132                     Nfail += scalar->data.S32;
    133 
    134                     // add these back onto sources
    135                     psArray *newSources = job->args->data[4];
    136                     for (int j = 0; j < newSources->n; j++) {
    137                         psArrayAdd (sources, 16, newSources->data[j]);
    138                     }
    139                 }
    140                 psFree(job);
    141             }
    142         }
     108# endif
     109        }
     110
     111        // wait for the threads to finish and manage results
     112        if (!psThreadPoolWait (false)) {
     113            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     114            return NULL;
     115        }
     116
     117        // we have only supplied one type of job, so we can assume the types here
     118        psThreadJob *job = NULL;
     119        while ((job = psThreadJobGetDone()) != NULL) {
     120            if (job->args->n < 1) {
     121                fprintf (stderr, "error with job\n");
     122            } else {
     123                psScalar *scalar = NULL;
     124                scalar = job->args->data[5];
     125                Nfit += scalar->data.S32;
     126                scalar = job->args->data[6];
     127                Npsf += scalar->data.S32;
     128                scalar = job->args->data[7];
     129                Next += scalar->data.S32;
     130                scalar = job->args->data[8];
     131                Nfail += scalar->data.S32;
     132
     133                // add these back onto sources
     134                psArray *newSources = job->args->data[4];
     135                for (int j = 0; j < newSources->n; j++) {
     136                    psArrayAdd (sources, 16, newSources->data[j]);
     137                }
     138            }
     139            psFree(job);
     140            }
    143141    }
    144142    psFree (cellGroups);
     
    225223
    226224        // replace object in image
    227         if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     225        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
     226            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     227        }
     228        Nfit ++;
     229
     230        // try fitting PSFs or extended sources depending on source->mode
     231        // these functions subtract the resulting fitted source
     232        if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
     233            if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
     234                source->type = PM_SOURCE_TYPE_EXTENDED;
     235                psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
     236                Next ++;
     237                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     238                continue;
     239            }
     240        } else {
     241            if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
     242                source->type = PM_SOURCE_TYPE_STAR;
     243                psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
     244                Npsf ++;
     245                source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;
     246                continue;
     247            }
     248        }
     249
     250        psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
     251        Nfail ++;
     252
     253        // re-subtract the object, leave local sky
     254        pmSourceCacheModel (source, maskVal);
     255        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
     256        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     257    }
     258
     259    // change the value of a scalar on the array (wrap this and put it in psArray.h)
     260    scalar = job->args->data[5];
     261    scalar->data.S32 = Nfit;
     262
     263    scalar = job->args->data[6];
     264    scalar->data.S32 = Npsf;
     265
     266    scalar = job->args->data[7];
     267    scalar->data.S32 = Next;
     268
     269    scalar = job->args->data[8];
     270    scalar->data.S32 = Nfail;
     271
     272    return true;
     273}
     274
     275# if (0)
     276bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources) {
     277
     278    bool status = false;
     279    int Nfit = 0;
     280    int Npsf = 0;
     281    int Next = 0;
     282    int Nfail = 0;
     283
     284    // bit-masks to test for good/bad pixels
     285    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     286    assert (maskVal);
     287
     288    // bit-mask to mark pixels not used in analysis
     289    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     290    assert (markVal);
     291
     292    // maskVal is used to test for rejected pixels, and must include markVal
     293    maskVal |= markVal;
     294
     295    // S/N limit to perform full non-linear fits
     296    float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM");
     297
     298    // option to limit analysis to a specific region
     299    char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION");
     300    psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region));
     301    if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
     302
     303    for (int i = 0; i < sources->n; i++) {
     304        pmSource *source = sources->data[i];
     305
     306        // skip non-astronomical objects (very likely defects)
     307        if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
     308        if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) continue;
     309        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     310        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     311
     312        // skip DBL second sources (ie, added by psphotFitBlob)
     313        if (source->mode &  PM_SOURCE_MODE_PAIR) continue;
     314
     315        // limit selection to some SN limit
     316        if (source->peak->SN < FIT_SN_LIM) continue;
     317
     318        // exclude sources outside optional analysis region
     319        if (source->peak->xf < AnalysisRegion.x0) continue;
     320        if (source->peak->yf < AnalysisRegion.y0) continue;
     321        if (source->peak->xf > AnalysisRegion.x1) continue;
     322        if (source->peak->yf > AnalysisRegion.y1) continue;
     323
     324        // if model is NULL, we don't have a starting guess
     325        if (source->modelPSF == NULL) continue;
     326
     327        // skip sources which are insignificant flux?
     328        // XXX this is somewhat ad-hoc
     329        if (source->modelPSF->params->data.F32[1] < 0.1) {
     330            psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n",
     331                     source->modelPSF->params->data.F32[1],
     332                     source->modelPSF->params->data.F32[2],
     333                     source->modelPSF->params->data.F32[3]);
     334            continue;
     335        }
     336
     337        // replace object in image
     338        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    228339            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    229340        }
     
    254365        pmSourceCacheModel (source, maskVal);
    255366        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    256         source->mode |= PM_SOURCE_MODE_SUBTRACTED;
    257     }
    258 
    259     // change the value of a scalar on the array (wrap this and put it in psArray.h)
    260     scalar = job->args->data[5];
    261     scalar->data.S32 = Nfit;
    262 
    263     scalar = job->args->data[6];
    264     scalar->data.S32 = Npsf;
    265 
    266     scalar = job->args->data[7];
    267     scalar->data.S32 = Next;
    268 
    269     scalar = job->args->data[8];
    270     scalar->data.S32 = Nfail;
    271 
    272     return true;
    273 }
    274 
    275 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources) {
    276 
    277     bool status = false;
    278     int Nfit = 0;
    279     int Npsf = 0;
    280     int Next = 0;
    281     int Nfail = 0;
    282 
    283     // bit-masks to test for good/bad pixels
    284     psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
    285     assert (maskVal);
    286 
    287     // bit-mask to mark pixels not used in analysis
    288     psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
    289     assert (markVal);
    290 
    291     // maskVal is used to test for rejected pixels, and must include markVal
    292     maskVal |= markVal;
    293 
    294     // S/N limit to perform full non-linear fits
    295     float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM");
    296 
    297     // option to limit analysis to a specific region
    298     char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION");
    299     psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region));
    300     if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined");
    301 
    302     for (int i = 0; i < sources->n; i++) {
    303         pmSource *source = sources->data[i];
    304 
    305         // skip non-astronomical objects (very likely defects)
    306         if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
    307         if (source->mode &  PM_SOURCE_MODE_CR_LIMIT) continue;
    308         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
    309         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
    310 
    311         // skip DBL second sources (ie, added by psphotFitBlob)
    312         if (source->mode &  PM_SOURCE_MODE_PAIR) continue;
    313 
    314         // limit selection to some SN limit
    315         if (source->peak->SN < FIT_SN_LIM) continue;
    316 
    317         // exclude sources outside optional analysis region
    318         if (source->peak->xf < AnalysisRegion.x0) continue;
    319         if (source->peak->yf < AnalysisRegion.y0) continue;
    320         if (source->peak->xf > AnalysisRegion.x1) continue;
    321         if (source->peak->yf > AnalysisRegion.y1) continue;
    322 
    323         // if model is NULL, we don't have a starting guess
    324         if (source->modelPSF == NULL) continue;
    325 
    326         // skip sources which are insignificant flux?
    327         // XXX this is somewhat ad-hoc
    328         if (source->modelPSF->params->data.F32[1] < 0.1) {
    329             psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n",
    330                      source->modelPSF->params->data.F32[1],
    331                      source->modelPSF->params->data.F32[2],
    332                      source->modelPSF->params->data.F32[3]);
    333             continue;
    334         }
    335 
    336         // replace object in image
    337         if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    338             pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    339         }
    340         Nfit ++;
    341 
    342         // try fitting PSFs or extended sources depending on source->mode
    343         // these functions subtract the resulting fitted source
    344         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    345             if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {
    346                 source->type = PM_SOURCE_TYPE_EXTENDED;
    347                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);
    348                 Next ++;
    349                 continue;
    350             }
    351         } else {
    352             if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {
    353                 source->type = PM_SOURCE_TYPE_STAR;
    354                 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);
    355                 Npsf ++;
    356                 continue;
    357             }
    358         }
    359 
    360         psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf);
    361         Nfail ++;
    362 
    363         // re-subtract the object, leave local sky
    364         pmSourceCacheModel (source, maskVal);
    365         pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    366         source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     367        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    367368    }
    368369
     
    375376    return true;
    376377}
     378# endif
  • branches/cnb_branch_20090215/psphot/src/psphotDeblendSatstars.c

    r20453 r21536  
    111111       
    112112        // any peaks within this contour should be dropped (mark as blend, drop after loop is done)
    113         // also drop any peaks which are too close to this peal
     113        // also drop any peaks which are too close to this peak
    114114        psVector *xv = contour->data[0];
    115115        psVector *yv = contour->data[1];
  • branches/cnb_branch_20090215/psphot/src/psphotDetectReadout.c

    r21392 r21536  
    2222    // Generate the mask and weight images, including the user-defined analysis region of interest
    2323    psphotSetMaskAndWeight (config, readout, recipe);
    24     if (!strcasecmp (breakPt, "NOTHING")) {
    25         return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL);
    26     }
    2724
    2825    // load the psf model, if suppled.  FWHM_X,FWHM_Y,etc are saved in the recipe
     
    3835
    3936    // include externally-supplied sources (supplied as PSPHOT.INPUT.CMF)
    40     pmDetections *detections = psphotDetectionsFromSources (config, inSources);
    41     if (!detections || !detections->peaks) {
    42         psError(PSPHOT_ERR_ARGUMENTS, true, "Can't find PSF stars");
    43         return psphotReadoutCleanup(config, readout, recipe, detections, NULL, NULL);
    44     }
    45 
    46     // construct sources and measure basic stats
    47     psArray *sources = psphotSourceStats (config, readout, detections);
    48     if (!sources) return false;
    49     if (!strcasecmp (breakPt, "PEAKS")) {
    50         return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    51     }
    52 
    53     // classify sources based on moments, brightness
    54     if (!psphotRoughClass (readout, sources, recipe, havePSF)) {
    55         psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image");
    56         return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);
    57     }
     37    psphotSetSourceParams (config, sources, psf);
    5838
    5939    // calculate source magnitudes
     
    6343    return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);
    6444}
     45
     46// deep in pmSourcePixelWeight, we need the following items for each location of interest:
     47// pmModel *model (should be a realized version of the PSF, can have unity normalization)
     48// psImage *mask  (local subimage of mask for source)
     49// psImageMaskType maskVal (from recipe & mask header)
     50
     51{
     52    pmModel *model = pmModelFromPSFforXY (psf, x, y, 1.0);
     53}
     54
  • branches/cnb_branch_20090215/psphot/src/psphotExtendedSourceAnalysis.c

    r21183 r21536  
    6161
    6262        // replace object in image
    63         if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     63        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    6464            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    6565        }
     
    7373                psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    7474                pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    75                 source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     75                source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    7676                continue;
    7777            }
     78            source->mode |= PM_SOURCE_MODE_RADIAL_FLUX;
    7879        }
    7980
     
    8586                psTrace ("psphot", 5, "measured isophotal mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    8687                Nisophot ++;
     88                source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
    8789            }
    8890        }
     
    9597                psTrace ("psphot", 5, "measured petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    9698                Npetro ++;
     99                source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
    97100            }
    98101        }
     
    105108                psTrace ("psphot", 5, "measure kron mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    106109                Nkron ++;
     110                source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
    107111            }
    108112        }
     
    116120            psTrace ("psphot", 5, "measured annuli for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My);
    117121            Nannuli ++;
     122            source->mode |= PM_SOURCE_MODE_EXTENDED_STATS;
    118123        }
    119124
    120125        // re-subtract the object, leave local sky
    121126        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    122         source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     127        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    123128    }
    124129
  • branches/cnb_branch_20090215/psphot/src/psphotExtendedSourceFits.c

    r21183 r21536  
    110110
    111111        // replace object in image
    112         if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     112        if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) {
    113113            pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    114114        }
     
    170170              if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {
    171171                  NconvolvePass ++;
     172                  source->mode |= PM_SOURCE_MODE_EXTENDED_FIT;
    172173              }
    173174          } else {
     
    184185              if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) {
    185186                  NplainPass ++;
     187                  source->mode |= PM_SOURCE_MODE_EXTENDED_FIT;
    186188              }
    187189          }
     
    224226
    225227          pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    226           source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     228          source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    227229
    228230          psFree (modelFluxes);
     
    251253        // subtract the best fit from the object, leave local sky
    252254        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    253         source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     255        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    254256
    255257        // the initial model flux is no longer needed
  • branches/cnb_branch_20090215/psphot/src/psphotFindPeaks.c

    r20453 r21536  
    2121    }
    2222
    23     // correct the peak values to S/N = sqrt(significance)
    24     // get the peak flux from the unsmoothed image
    25     // the peak pixel coords are guaranteed to be on the image
     23    // Convert the peak values to S/N = sqrt(significance).
     24    // Get the peak flux from the unsmoothed image.
     25    // Rescale the peak position errors using the peak variance
     26    // The peak pixel coords are guaranteed to be on the image
    2627    int row0 = readout->image->row0;
    2728    int col0 = readout->image->col0;
     
    3031        peak->SN = sqrt(peak->value);
    3132        peak->flux = readout->image->data.F32[peak->y-row0][peak->x-col0];
     33        if (readout->variance && isfinite (peak->dx)) {
     34            peak->dx *= sqrt(readout->variance->data.F32[peak->y-row0][peak->x-col0]);
     35        }
     36        if (readout->variance && isfinite (peak->dy)) {
     37            peak->dy *= sqrt(readout->variance->data.F32[peak->y-row0][peak->x-col0]);
     38        }
    3239    }
    3340
  • branches/cnb_branch_20090215/psphot/src/psphotFitSourcesLinear.c

    r21366 r21536  
    6363        pmSource *source = sources->data[i];
    6464
     65        // turn this bit off and turn it on again if we pass this test
     66        source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;
     67
    6568        // skip non-astronomical objects (very likely defects)
    6669        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
    6770        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
    6871
    69         // if (source->type == PM_SOURCE_TYPE_STAR &&
     72        // do not include CRs in the full ensemble fit
    7073        if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
    7174
    7275        if (final) {
    73             if (source->mode &  PM_SOURCE_MODE_SUBTRACTED) continue;
     76            if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
    7477        } else {
    75             if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
     78            if (source->mode & PM_SOURCE_MODE_BLEND) continue;
    7679        }
    7780
     
    9194        if (y > AnalysisRegion.y1) continue;
    9295
     96        source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
    9397        psArrayAdd (fitSources, 100, source);
    9498    }
     
    185189    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
    186190
     191    // XXXX **** philosophical question:
     192    // we measure bright objects in three passes: 1) linear fit; 2) non-linear fit; 3) linear fit:
     193    // should retain the chisq and errors from the intermediate non-linear fit?
     194    // the non-linear fit provides better values for the position errors, and for
     195    // extended sources, the shape errors
     196
    187197    // adjust I0 for fitSources and subtract
    188198    for (int i = 0; i < fitSources->n; i++) {
     
    194204            psAbort("linear fitted source is nan");
    195205        }
     206
    196207        model->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
    197208        model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
     
    200211        // subtract object
    201212        pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    202         source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     213        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    203214    }
    204215    psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "sub models: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
     
    207218    for (int i = 0; final && (i < fitSources->n); i++) {
    208219        pmSource *source = fitSources->data[i];
     220        if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue;
    209221        pmModel *model = pmSourceGetModel (NULL, source);
    210222        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal);
  • branches/cnb_branch_20090215/psphot/src/psphotGuessModels.c

    r21381 r21536  
    2222}
    2323
    24 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
    25 
    2624// construct an initial PSF model for each object
    2725bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) {
     
    6765        for (int j = 0; j < cells->n; j++) {
    6866
    69             if (nThreads) {
    70                 // allocate a job -- if threads are not defined, this just runs the job
    71                 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
    72                 psArrayAdd(job->args, 1, readout);
    73                 psArrayAdd(job->args, 1, cells->data[j]); // sources
    74                 psArrayAdd(job->args, 1, psf);
    75 
    76                 // XXX change these to use abstract mask type info
    77                 PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    78                 PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
    79 
    80                 if (!psThreadJobAddPending(job)) {
    81                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    82                     psFree (job);
    83                     return false;
    84                 }
    85                 psFree(job);
    86             } else {
     67            // allocate a job -- if threads are not defined, this just runs the job
     68            psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
     69            psArrayAdd(job->args, 1, readout);
     70            psArrayAdd(job->args, 1, cells->data[j]); // sources
     71            psArrayAdd(job->args, 1, psf);
     72
     73            // XXX change these to use abstract mask type info
     74            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     75            PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
     76
     77            if (!psThreadJobAddPending(job)) {
     78                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     79                psFree (job);
     80                return false;
     81            }
     82            psFree(job);
     83
     84# if (0)               
    8785                if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) {
    8886                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    8987                    return false;
    9088                }
    91             }
    92         }
    93 
    94         if (nThreads) {
    95             // wait for the threads to finish and manage results
    96             // wait here for the threaded jobs to finish
    97             // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
    98             if (!psThreadPoolWait (false)) {
    99                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    100                 return false;
    101             }
    102 
    103             // we have only supplied one type of job, so we can assume the types here
    104             psThreadJob *job = NULL;
    105             while ((job = psThreadJobGetDone()) != NULL) {
    106                 // we have no returned data from this operation
    107                 if (job->args->n < 1) {
    108                     fprintf (stderr, "error with job\n");
    109                 }
    110                 psFree(job);
    111             }
     89# endif
     90        }
     91
     92        // wait for the threads to finish and manage results
     93        // wait here for the threaded jobs to finish
     94        // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
     95        if (!psThreadPoolWait (false)) {
     96            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     97            return false;
     98        }
     99
     100        // we have only supplied one type of job, so we can assume the types here
     101        psThreadJob *job = NULL;
     102        while ((job = psThreadJobGetDone()) != NULL) {
     103            // we have no returned data from this operation
     104            if (job->args->n < 1) {
     105                fprintf (stderr, "error with job\n");
     106            }
     107            psFree(job);
    112108        }
    113109    }
     
    116112    int nMiss = 0;
    117113    for (int i = 0; i < sources->n; i++) {
    118 
    119114        pmSource *source = sources->data[i];
    120         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    121             source->mode &= ~PM_SOURCE_MODE_EXT_LIMIT;
     115        if (source->tmpFlags & PM_SOURCE_TMPF_MODEL_GUESS) {
    122116            continue;
    123117        }
    124 
    125118        nMiss ++;
    126119    }
    127     psLogMsg ("psphot.models", 4, "failed to build models for %d objects\n", nMiss);
     120    psAssert (nMiss == 0, "failed to attempt to build models for %d objects\n", nMiss);
    128121
    129122    psFree (cellGroups);
     
    148141        pmSource *source = sources->data[i];
    149142
    150         // XXXX this is just for a test: use this to mark sources for which the model is measured
    151         // check later that all are used.
    152         source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
     143        // this is used to mark sources for which the model is measured. We check later that
     144        // all are used.
     145        source->tmpFlags |= PM_SOURCE_TMPF_MODEL_GUESS;
    153146
    154147        // skip non-astronomical objects (very likely defects)
     
    185178        pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC X5
    186179        if (modelPSF == NULL) {
    187             psError(PSPHOT_ERR_PSF, false,
    188                     "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
     180            psWarning ("Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
    189181                    source->peak->y, source->peak->x);
    190             //
    191             // Try the centre of the image
    192             //
     182
     183            // Try the center of the image
    193184            modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
    194185            modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
    195186            modelPSF = pmModelFromPSF (modelEXT, psf);
    196187            if (modelPSF == NULL) {
    197                 psError(PSPHOT_ERR_PSF, false,
    198                         "Failed to determine PSF model at centre of image");
     188                psError(PSPHOT_ERR_PSF, false, "Failed to determine PSF model at center of image");
    199189                psFree(modelEXT);
    200190                return false;
    201191            }
    202 
    203192            source->mode |= PM_SOURCE_MODE_BADPSF;
    204193        }
     
    221210}
    222211
     212# if (0)
    223213// construct models only for sources in the specified region
    224214bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     
    301291    return true;
    302292}
     293# endif
  • branches/cnb_branch_20090215/psphot/src/psphotMagnitudes.c

    r21392 r21536  
    11# include "psphotInternal.h"
    2 
    3 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal);
    42
    53bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) {
     
    5957        for (int j = 0; j < cells->n; j++) {
    6058
    61             if (nThreads) {
    62                 // allocate a job -- if threads are not defined, this just runs the job
    63                 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES");
    64 
    65                 psArrayAdd(job->args, 1, cells->data[j]); // sources
    66                 psArrayAdd(job->args, 1, psf);
    67                 psArrayAdd(job->args, 1, binning);
    68                 psArrayAdd(job->args, 1, backModel);
    69                 psArrayAdd(job->args, 1, backStdev);
    70 
    71                 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
    72                 PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    73                 PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for nAp
    74 
    75                 if (!psThreadJobAddPending(job)) {
    76                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    77                     psFree (job);
    78                     return false;
    79                 }
    80                 psFree(job);
    81             } else {
     59            // allocate a job -- if threads are not defined, this just runs the job
     60            psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES");
     61
     62            psArrayAdd(job->args, 1, cells->data[j]); // sources
     63            psArrayAdd(job->args, 1, psf);
     64            psArrayAdd(job->args, 1, binning);
     65            psArrayAdd(job->args, 1, backModel);
     66            psArrayAdd(job->args, 1, backStdev);
     67
     68            PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
     69            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     70            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for nAp
     71
     72            if (!psThreadJobAddPending(job)) {
     73                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     74                psFree (job);
     75                return false;
     76            }
     77            psFree(job);
     78
     79# if (0)
    8280                int nap = 0;
    8381                if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) {
     
    8684                }
    8785                Nap += nap;
    88             }
    89         }
    90 
    91         if (nThreads) {
    92             // wait for the threads to finish and manage results
    93             if (!psThreadPoolWait (false)) {
    94                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    95                 return false;
    96             }
    97 
    98             // we have only supplied one type of job, so we can assume the types here
    99             psThreadJob *job = NULL;
    100             while ((job = psThreadJobGetDone()) != NULL) {
    101                 if (job->args->n < 1) {
    102                     fprintf (stderr, "error with job\n");
    103                 } else {
    104                     psScalar *scalar = job->args->data[7];
    105                     Nap += scalar->data.S32;
    106                 }
    107                 psFree(job);
    108             }
     86# endif
     87        }
     88
     89        // wait for the threads to finish and manage results
     90        if (!psThreadPoolWait (false)) {
     91            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     92            return false;
     93        }
     94
     95        // we have only supplied one type of job, so we can assume the types here
     96        psThreadJob *job = NULL;
     97        while ((job = psThreadJobGetDone()) != NULL) {
     98            if (job->args->n < 1) {
     99                fprintf (stderr, "error with job\n");
     100            } else {
     101                psScalar *scalar = job->args->data[7];
     102                Nap += scalar->data.S32;
     103            }
     104            psFree(job);
    109105        }
    110106    }
     
    162158}
    163159
     160# if (0)
    164161bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal) {
    165162
     
    198195    return true;
    199196}
     197# endif
    200198
    201199bool psphotPSFWeights(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources) {
     
    295293        }
    296294
    297         status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal);
     295        status = pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
    298296        if (!status) {
    299297          psTrace ("psphot", 3, "fail to measure pixel weight");
  • branches/cnb_branch_20090215/psphot/src/psphotMergeSources.c

    r21251 r21536  
    122122    return detections;
    123123}
     124
     125// generate the detection structure for the supplied array of sources
     126bool psphotSetSourceParams (pmConfig *config, psArray *sources, pmPSF *psf) {
     127
     128    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
     129    if (!recipe) {
     130        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSPHOT_RECIPE);
     131        return false;
     132    }
     133
     134    for (int i = 0; i < sources->n; i++) {
     135        pmSource *source = sources->data[i];
     136        pmModel *model = source->modelPSF;
     137
     138        if (source->mode & PSF_SOURCE_MASK || !isfinite(source->psfMag)) {
     139            continue;
     140        }
     141
     142        float flux = powf(10.0, -0.4 * source->psfMag);
     143        float xpos = model->params->data.F32[PM_PAR_XPOS];
     144        float ypos = model->params->data.F32[PM_PAR_YPOS];
     145
     146        pmPeak *peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE);
     147        peak->xf = xpos;
     148        peak->yf = ypos;
     149        peak->flux = flux; // this are being set wrong, but does it matter?
     150
     151        if (isfinite (source->errMag) && (source->errMag > 0.0)) {
     152          peak->SN = 1.0 / source->errMag;
     153        } else {
     154          peak->SN = 0.0;
     155        }
     156
     157        source->peak = peak;
     158    }
     159
     160    psLogMsg ("psphot", 3, "%ld PSF sources loaded", sources->n);
     161
     162    return true;
     163}
  • branches/cnb_branch_20090215/psphot/src/psphotReplaceUnfit.c

    r21183 r21536  
    1717    replace:
    1818        pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    19         source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
     19        source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    2020    }
    2121    psLogMsg ("psphot.replace", 3, "replace unfitted models: %f sec (%ld objects)\n", psTimerMark ("psphot.replace"), sources->n);
     
    3838
    3939      // replace other sources?
    40       if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) continue;
     40      if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
    4141
    4242      pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    43       source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
     43      source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    4444    }
    4545    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     
    6262
    6363      // replace other sources?
    64       if (source->mode & PM_SOURCE_MODE_SUBTRACTED) continue;
     64      if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
    6565
    6666      pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    67       source->mode |= PM_SOURCE_MODE_SUBTRACTED;
     67      source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    6868    }
    6969    psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace"));
     
    7575
    7676    // what is current state? (true : add; false : sub)
    77     bool state = !(source->mode & PM_SOURCE_MODE_SUBTRACTED);
     77    bool state = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    7878    if (state && useState) return true;
    7979
     
    8686
    8787    // what is current state? (true : sub; false : add)
    88     bool state = (source->mode & PM_SOURCE_MODE_SUBTRACTED);
     88    bool state = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    8989    if (state && useState) return true;
    9090
     
    9797
    9898    // what is desired state? (true : add; false : sub)
    99     bool newState = !(source->mode & PM_SOURCE_MODE_SUBTRACTED);
     99    bool newState = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    100100    if (curState == newState) return true;
    101101
  • branches/cnb_branch_20090215/psphot/src/psphotSourceFits.c

    r21183 r21536  
    120120        pmSourceCacheModel (blend, maskVal);
    121121        pmSourceSub (blend, PM_MODEL_OP_FULL, maskVal);
    122         blend->mode |=  PM_SOURCE_MODE_SUBTRACTED;
     122        blend->tmpFlags |=  PM_SOURCE_TMPF_SUBTRACTED;
     123        blend->mode |=  PM_SOURCE_MODE_BLEND_FIT;
    123124    }
    124125    NfitBlend += modelSet->n;
     
    143144    pmSourceCacheModel (source, maskVal);
    144145    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    145     source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
     146    source->tmpFlags |=  PM_SOURCE_TMPF_SUBTRACTED;
     147    source->mode |=  PM_SOURCE_MODE_BLEND_FIT;
    146148    return true;
    147149}
     
    184186    pmSourceCacheModel (source, maskVal);
    185187    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    186     source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
     188    source->tmpFlags |=  PM_SOURCE_TMPF_SUBTRACTED;
    187189    return true;
    188190}
     
    285287    pmSourceCacheModel (source, maskVal);
    286288    pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
    287     source->mode |=  PM_SOURCE_MODE_SUBTRACTED;
     289    source->tmpFlags |=  PM_SOURCE_TMPF_SUBTRACTED;
    288290    psTrace ("psphot", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[PM_PAR_XPOS], EXT->params->data.F32[PM_PAR_YPOS]);
    289291    return true;
     
    296298    psFree (source->modelPSF);
    297299    source->modelPSF = psMemIncrRefCounter (DBL->data[0]);
    298     source->mode    |= PM_SOURCE_MODE_SUBTRACTED;
    299     source->mode    |= PM_SOURCE_MODE_PAIR;
     300    source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     301    source->mode     |= PM_SOURCE_MODE_PAIR;
    300302
    301303    // copy most data from the primary source (modelEXT, blends stay NULL)
  • branches/cnb_branch_20090215/psphot/src/psphotSourceSize.c

    r21366 r21536  
    5656
    5757        // source must have been subtracted
    58         if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) {
     58        if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {
     59            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
    5960            psTrace("psphot", 7, "Not calculating extNsigma,crNsigma since source is not subtracted\n");
    6061            continue;
     
    6364        psF32 **resid  = source->pixels->data.F32;
    6465        psF32 **variance = source->variance->data.F32;
    65         psImageMaskType **mask    = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
     66        psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;
    6667
    6768        // check for extendedness: measure the delta flux significance at the 1 sigma contour
     
    8283        if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||
    8384            yPeak < 1 || yPeak > source->pixels->numRows - 2) {
     85            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
    8486            psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");
    8587            continue;
     
    98100        if (!keep) {
    99101            psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");
     102            source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;
    100103            continue;
    101104        }
     
    156159        }
    157160        source->crNsigma  = (nCR > 0)  ? fCR / nCR : 0.0;
    158         if (!isfinite(source->crNsigma)) continue;
     161        if (!isfinite(source->crNsigma)) {
     162            continue;
     163        }
    159164
    160165        // this source is thought to be a cosmic ray.  flag the detection and mask the pixels
     
    264269    // replace the source flux
    265270    pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
    266     source->mode &= ~PM_SOURCE_MODE_SUBTRACTED;
     271    source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    267272
    268273    // flag this as a CR
  • branches/cnb_branch_20090215/psphot/src/psphotSourceStats.c

    r21359 r21536  
    11# include "psphotInternal.h"
    2 
    3 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe);
    42
    53psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections) {
     
    8078        for (int j = 0; j < cells->n; j++) {
    8179
    82             if (nThreads) {
    83                 // allocate a job -- if threads are not defined, this just runs the job
    84                 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS");
    85 
    86                 psArrayAdd(job->args, 1, cells->data[j]); // sources
    87                 psArrayAdd(job->args, 1, recipe);
    88                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments
    89                 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
    90 
    91                 if (!psThreadJobAddPending(job)) {
    92                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    93                     psFree (job);
    94                     return NULL;
    95                 }
    96                 psFree(job);
    97             } else {
     80            // allocate a job -- if threads are not defined, this just runs the job
     81            psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS");
     82
     83            psArrayAdd(job->args, 1, cells->data[j]); // sources
     84            psArrayAdd(job->args, 1, recipe);
     85            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments
     86            PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail
     87
     88            if (!psThreadJobAddPending(job)) {
     89                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     90                psFree (job);
     91                return NULL;
     92            }
     93            psFree(job);
     94
     95# if (0)
    9896                int nfail = 0;
    9997                int nmoments = 0;
     
    104102                Nfail += nfail;
    105103                Nmoments += nmoments;
     104# endif
     105        }
     106
     107        // wait for the threads to finish and manage results
     108        if (!psThreadPoolWait (false)) {
     109            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     110            return NULL;
     111        }
     112
     113        // we have only supplied one type of job, so we can assume the types here
     114        psThreadJob *job = NULL;
     115        while ((job = psThreadJobGetDone()) != NULL) {
     116            if (job->args->n < 1) {
     117                fprintf (stderr, "error with job\n");
     118            } else {
     119                psScalar *scalar = NULL;
     120                scalar = job->args->data[2];
     121                Nmoments += scalar->data.S32;
     122                scalar = job->args->data[3];
     123                Nfail += scalar->data.S32;
    106124            }
    107         }
    108 
    109         if (nThreads) {
    110             // wait for the threads to finish and manage results
    111             if (!psThreadPoolWait (false)) {
    112                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    113                 return NULL;
    114             }
    115 
    116             // we have only supplied one type of job, so we can assume the types here
    117             psThreadJob *job = NULL;
    118             while ((job = psThreadJobGetDone()) != NULL) {
    119                 if (job->args->n < 1) {
    120                     fprintf (stderr, "error with job\n");
    121                 } else {
    122                     psScalar *scalar = NULL;
    123                     scalar = job->args->data[2];
    124                     Nmoments += scalar->data.S32;
    125                     scalar = job->args->data[3];
    126                     Nfail += scalar->data.S32;
    127                 }
    128                 psFree(job);
    129             }
     125            psFree(job);
    130126        }
    131127    }
     
    148144    psArray *sources                = job->args->data[0];
    149145    psMetadata *recipe              = job->args->data[1];
     146
     147    float INNER    = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
     148    if (!status) return false;
     149    float MIN_SN   = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN");
     150    if (!status) return false;
     151    float RADIUS   = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
     152    if (!status) return false;
     153
     154    // bit-masks to test for good/bad pixels
     155    psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
     156    assert (maskVal);
     157
     158    // bit-mask to mark pixels not used in analysis
     159    psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
     160    assert (markVal);
     161
     162    // maskVal is used to test for rejected pixels, and must include markVal
     163    maskVal |= markVal;
     164
     165    // threaded measurement of the sources moments
     166    int Nfail = 0;
     167    int Nmoments = 0;
     168    for (int i = 0; i < sources->n; i++) {
     169        pmSource *source = sources->data[i];
     170
     171        // skip faint sources for moments measurement
     172        if (source->peak->SN < MIN_SN) {
     173            source->mode |= PM_SOURCE_MODE_BELOW_MOMENTS_SN;
     174            continue;
     175        }
     176
     177        // measure a local sky value
     178        // the local sky is now ignored; kept here for reference only
     179        status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);
     180        if (!status) {
     181            source->mode |= PM_SOURCE_MODE_SKY_FAILURE;
     182            psErrorClear(); // XXX re-consider the errors raised here
     183            Nfail ++;
     184            continue;
     185        }
     186
     187        // measure the local sky variance (needed if noise is not sqrt(signal))
     188        // XXX EAM : this should use ROBUST not SAMPLE median, but it is broken
     189        status = pmSourceLocalSkyVariance (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);
     190        if (!status) {
     191            source->mode |= PM_SOURCE_MODE_SKYVAR_FAILURE;
     192            Nfail ++;
     193            psErrorClear();
     194            continue;
     195        }
     196
     197        // measure basic source moments
     198        status = pmSourceMoments (source, RADIUS);
     199        if (status) {
     200            Nmoments ++;
     201            continue;
     202        }
     203
     204        // if no valid pixels, or massive swing, likely saturated source,
     205        // try a much larger box
     206        BIG_RADIUS = PS_MIN (INNER, 3*RADIUS);
     207        psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
     208        status = pmSourceMoments (source, BIG_RADIUS);
     209        if (status) {
     210            source->mode |= PM_SOURCE_MODE_BIG_RADIUS;
     211            Nmoments ++;
     212            continue;
     213        }
     214
     215        source->mode |= PM_SOURCE_MODE_MOMENTS_FAILURE;
     216        Nfail ++;
     217        psErrorClear();
     218        continue;
     219    }
     220
     221    // change the value of a scalar on the array (wrap this and put it in psArray.h)
     222    scalar = job->args->data[2];
     223    scalar->data.S32 = Nmoments;
     224
     225    scalar = job->args->data[3];
     226    scalar->data.S32 = Nfail;
     227   
     228    return true;
     229}
     230
     231# if (0)
     232bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe) {
     233
     234    bool status = false;
     235    float BIG_RADIUS;
    150236
    151237    float INNER    = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
     
    219305
    220306    // change the value of a scalar on the array (wrap this and put it in psArray.h)
    221     scalar = job->args->data[2];
    222     scalar->data.S32 = Nmoments;
    223 
    224     scalar = job->args->data[3];
    225     scalar->data.S32 = Nfail;
    226    
    227     return true;
    228 }
    229 
    230 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe) {
    231 
    232     bool status = false;
    233     float BIG_RADIUS;
    234 
    235     float INNER    = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");
    236     if (!status) return false;
    237     float MIN_SN   = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN");
    238     if (!status) return false;
    239     float RADIUS   = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");
    240     if (!status) return false;
    241 
    242     // bit-masks to test for good/bad pixels
    243     psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");
    244     assert (maskVal);
    245 
    246     // bit-mask to mark pixels not used in analysis
    247     psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");
    248     assert (markVal);
    249 
    250     // maskVal is used to test for rejected pixels, and must include markVal
    251     maskVal |= markVal;
    252 
    253     // threaded measurement of the sources moments
    254     int Nfail = 0;
    255     int Nmoments = 0;
    256     for (int i = 0; i < sources->n; i++) {
    257         pmSource *source = sources->data[i];
    258 
    259         // skip faint sources for moments measurement
    260         if (source->peak->SN < MIN_SN) {
    261             continue;
    262         }
    263 
    264         // measure a local sky value
    265         // the local sky is now ignored; kept here for reference only
    266         status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);
    267         if (!status) {
    268             psErrorClear(); // XXX re-consider the errors raised here
    269             Nfail ++;
    270             continue;
    271         }
    272 
    273         // measure the local sky variance (needed if noise is not sqrt(signal))
    274         // XXX EAM : this should use ROBUST not SAMPLE median, but it is broken
    275         status = pmSourceLocalSkyVariance (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);
    276         if (!status) {
    277             Nfail ++;
    278             psErrorClear();
    279             continue;
    280         }
    281 
    282         // measure basic source moments
    283         status = pmSourceMoments (source, RADIUS);
    284         if (status) {
    285             Nmoments ++;
    286             continue;
    287         }
    288 
    289         // if no valid pixels, or massive swing, likely saturated source,
    290         // try a much larger box
    291         BIG_RADIUS = PS_MIN (INNER, 3*RADIUS);
    292         psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y);
    293         status = pmSourceMoments (source, BIG_RADIUS);
    294         if (status) {
    295             Nmoments ++;
    296             continue;
    297         }
    298 
    299         Nfail ++;
    300         psErrorClear();
    301         continue;
    302     }
    303 
    304     // change the value of a scalar on the array (wrap this and put it in psArray.h)
    305307    *nmoments = Nmoments;
    306308    *nfail = Nfail;
     
    308310    return true;
    309311}
     312# endif
  • branches/cnb_branch_20090215/psphot/src/psphotVisual.c

    r21366 r21536  
    1818// these are invoked by the -visual options
    1919
    20 static bool isVisual = false;
    2120static int kapa = -1;
    2221static int kapa2 = -1;
    2322static int kapa3 = -1;
    2423
    25 bool psphotSetVisual (bool mode) {
    26 
    27     isVisual = mode;
    28     return true;
    29 }
    3024
    3125bool psphotVisualShowMask (int kapaFD, psImage *inImage, const char *name, int channel) {
     
    135129bool psphotVisualShowImage (pmReadout *readout) {
    136130
    137     if (!isVisual) return true;
     131    if (!pmVisualIsVisual()) return true;
    138132
    139133    if (kapa == -1) {
     
    141135        if (kapa == -1) {
    142136            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    143             isVisual = false;
     137            pmVisualSetVisual(false);
    144138            return false;
    145139        }
     
    164158    pmReadout *backgnd;
    165159
    166     if (!isVisual) return true;
     160    if (!pmVisualIsVisual()) return true;
    167161
    168162    if (kapa == -1) {
     
    170164        if (kapa == -1) {
    171165            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    172             isVisual = false;
     166            pmVisualSetVisual(false);
    173167            return false;
    174168        }
     
    199193bool psphotVisualShowSignificance (psImage *image) {
    200194
    201     if (!isVisual) return true;
     195    if (!pmVisualIsVisual()) return true;
    202196
    203197    if (kapa == -1) {
     
    205199        if (kapa == -1) {
    206200            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    207             isVisual = false;
     201            pmVisualSetVisual(false);
    208202            return false;
    209203        }
     
    228222    KiiOverlay *overlay;
    229223
    230     if (!isVisual) return true;
     224    if (!pmVisualIsVisual()) return true;
    231225
    232226    if (kapa == -1) {
     
    306300    KiiOverlay *overlay;
    307301
    308     if (!isVisual) return true;
     302    if (!pmVisualIsVisual()) return true;
    309303
    310304    if (kapa == -1) {
     
    423417    psEllipseAxes axes;
    424418
    425     if (!isVisual) return true;
     419    if (!pmVisualIsVisual()) return true;
    426420
    427421    if (kapa == -1) {
     
    478472    Graphdata graphdata;
    479473
    480     if (!isVisual) return true;
     474    if (!pmVisualIsVisual()) return true;
    481475
    482476    if (kapa3 == -1) {
     
    484478        if (kapa3 == -1) {
    485479            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    486             isVisual = false;
     480            pmVisualSetVisual(false);
    487481            return false;
    488482        }
     
    694688bool psphotVisualShowRoughClass (psArray *sources) {
    695689
    696     if (!isVisual) return true;
     690    if (!pmVisualIsVisual()) return true;
    697691
    698692    if (kapa == -1) {
     
    723717bool psphotVisualShowPSFModel (pmReadout *readout, pmPSF *psf) {
    724718
    725     if (!isVisual) return true;
     719    if (!pmVisualIsVisual()) return true;
    726720
    727721    if (kapa2 == -1) {
     
    729723        if (kapa2 == -1) {
    730724            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    731             isVisual = false;
     725            pmVisualSetVisual(false);
    732726            return false;
    733727        }
     
    801795    bool status;
    802796
    803     if (!isVisual) return true;
     797    if (!pmVisualIsVisual()) return true;
    804798
    805799    if (kapa2 == -1) {
     
    807801        if (kapa2 == -1) {
    808802            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    809             isVisual = false;
     803            pmVisualSetVisual(false);
    810804            return false;
    811805        }
     
    961955    bool status;
    962956
    963     if (!isVisual) return true;
     957    if (!pmVisualIsVisual()) return true;
    964958
    965959    if (kapa2 == -1) {
     
    967961        if (kapa2 == -1) {
    968962            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    969             isVisual = false;
     963            pmVisualSetVisual(false);
    970964            return false;
    971965        }
     
    11011095    Graphdata graphdata;
    11021096
    1103     bool state = !(source->mode & PM_SOURCE_MODE_SUBTRACTED);
     1097    bool state = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);
    11041098    psphotAddWithTest (source, true, maskVal); // replace source if subtracted
    11051099
     
    12141208    KapaSection section;  // put the positive profile in one and the residuals in another?
    12151209
    1216     if (!isVisual) return true;
     1210    if (!pmVisualIsVisual()) return true;
    12171211
    12181212    if (kapa3 == -1) {
     
    12201214        if (kapa3 == -1) {
    12211215            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    1222             isVisual = false;
     1216            pmVisualSetVisual(false);
    12231217            return false;
    12241218        }
     
    12861280    psEllipseAxes axes;
    12871281
    1288     if (!isVisual) return true;
     1282    if (!pmVisualIsVisual()) return true;
    12891283
    12901284    if (kapa == -1) {
     
    13871381    KiiOverlay *overlay;
    13881382
    1389     if (!isVisual) return true;
     1383    if (!pmVisualIsVisual()) return true;
    13901384
    13911385    if (kapa == -1) {
     
    14641458    KapaSection section;
    14651459
    1466     if (!isVisual) return true;
     1460    if (!pmVisualIsVisual()) return true;
    14671461
    14681462    if (kapa3 == -1) {
     
    14701464        if (kapa3 == -1) {
    14711465            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    1472             isVisual = false;
     1466            pmVisualSetVisual(false);
    14731467            return false;
    14741468        }
     
    16041598bool psphotVisualShowResidualImage (pmReadout *readout) {
    16051599
    1606     if (!isVisual) return true;
     1600    if (!pmVisualIsVisual()) return true;
    16071601
    16081602    if (kapa == -1) {
     
    16101604        if (kapa == -1) {
    16111605            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    1612             isVisual = false;
     1606            pmVisualSetVisual(false);
    16131607            return false;
    16141608        }
     
    16311625    Graphdata graphdata;
    16321626
    1633     if (!isVisual) return true;
     1627    if (!pmVisualIsVisual()) return true;
    16341628
    16351629    if (kapa3 == -1) {
     
    16371631        if (kapa3 == -1) {
    16381632            fprintf (stderr, "failure to open kapa; visual mode disabled\n");
    1639             isVisual = false;
     1633            pmVisualSetVisual(false);
    16401634            return false;
    16411635        }
     
    17121706# else
    17131707
    1714 bool psphotSetVisual (bool mode){}
    17151708bool psphotVisualShowImage (pmConfig *config, pmReadout *readout) { return true; }
    17161709bool psphotVisualShowBackground (pmConfig *config, const pmFPAview *view, pmReadout *readout) { return true; }
  • branches/cnb_branch_20090215/pswarp/src/pswarpArguments.c

    r21368 r21536  
    66 *
    77 *  @author IfA
    8  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2009-02-06 03:10:36 $
     8 *  @version $Revision: 1.24.2.1 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2009-02-19 17:59:50 $
    1010 *  Copyright 2009 Institute for Astronomy, University of Hawaii
    1111 */
     
    3939    {
    4040        int arg;                        ///< Argument Number
    41         if ((arg = psArgumentGet(argc, argv, "-psphot-visual"))) {
     41        if ((arg = psArgumentGet(argc, argv, "-visual"))) {
    4242            psArgumentRemove(arg, &argc, argv);
    43             psphotSetVisual(true);
     43            pmVisualSetVisual(true);
    4444        }
    4545    }
Note: See TracChangeset for help on using the changeset viewer.